![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Memory allocation and deallocation definitions. More...
#include <stdlib.h>#include <stdio.h>#include <string.h>#include "rnr/rnrconfig.h"#include "rnr/new.h"Go to the source code of this file.
Functions | |
| void * | new (size_t size) |
| new() "operator" More... | |
| void * | new_overs (void *pSrc, size_t sizeDup, size_t sizeNew) |
| Allocate and duplicate. More... | |
| void * | new_memdup (size_t size, void *data) |
| Duplicate data. More... | |
| char * | new_strdup (const char *s) |
| Duplicate a string. More... | |
| char * | new_strndup (const char *s, size_t n) |
| Duplicate not more than n characters of string. More... | |
Memory allocation and deallocation definitions.
General purpose dynamic memory allocate and deallocate definitions. None of the calls will fail, unless fatally for the entire program. Modeled on C++ new() and delete() operators.
The current implementation uses the malloc() and free() standard library calls.
Definition in file new.c.
| void* new | ( | size_t | size | ) |
new() "operator"
Dynamic memory allocator. All allocated data are zero'ed (i.e. set to 0).
| size | Number of bytes. |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
Definition at line 73 of file new.c.
References EC_ERROR, and NULL.
| void* new_memdup | ( | size_t | size, |
| void * | data | ||
| ) |
Duplicate data.
| size | Number of bytes. |
| data | Data to duplicate |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
Definition at line 146 of file new.c.
References NULL.
Referenced by delete().
| void* new_overs | ( | void * | pSrc, |
| size_t | sizeDup, | ||
| size_t | sizeNew | ||
| ) |
Allocate and duplicate.
A new block a memory of sizeNew bytes is allocated. sizeDup bytes from the source data are copied to the new block. All allocated, but not duplicated data are zero'ed (i.e. set to 0).
| pSrc | Source memory block to duplicate. |
| sizeDup | Number of bytes to duplicate, with sizeDup <= sizeNew. |
| sizeNew | Number of bytes for new block. |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
| Bad Sizes | Program is terminated with exit code EC_ERROR. |
Definition at line 112 of file new.c.
References EC_ERROR.
Referenced by delete(), grow_table(), and shrink_table().
| char* new_strdup | ( | const char * | s | ) |
Duplicate a string.
| s | Null terminated string to duplicate. |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
Definition at line 176 of file new.c.
Referenced by ConfigDbNew(), ConfigDbSetName(), ConfigSectionAddPair(), ConfigSectionNew(), delete(), force_grow(), LOG_ATTACH_LOGFP(), LOG_SET_LOGFILE(), LOGGER(), LOGGER_CALL(), main(), NewExpandTilde(), NewNormPath(), NewZooAnimal(), OptsCvtArgStr(), SocketAddrName(), SocketAttrSetLocalName(), SocketAttrSetRemoteName(), SocketThisHostName(), test_hash(), UriParseNew(), UriSetHostName(), UriSetPath(), and UriSetScheme().
| char* new_strndup | ( | const char * | s, |
| size_t | n | ||
| ) |
Duplicate not more than n characters of string.
Duplicate the first n characters of string or until a null character is encounter, whichever comes first. Guaranteed to return a null terminated string.
| s | String to duplicate. |
| n | Maximum number of characters to duplicate. |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
Definition at line 208 of file new.c.
Referenced by delete(), NewSearchPathExpanded(), UriParseHostNew(), and UriParseNew().