![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Memory allocation and deallocation declarations. More...
Go to the source code of this file.
Macros | |
| #define | NEW(T) (T *)new(sizeof(T)) |
| Allocate new type. More... | |
| #define | NEWSTR(len) (char *)new( sizeof(char)*((size_t)((len)+1)) ) |
| Allocate new string buffer of length len+1. More... | |
Functions | |
| INLINE_IN_H void | delete (void *p) |
| delete() "operator" More... | |
| 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... | |
| char * | strcpy_s (char *dest, size_t n, const char *src) |
| Copy source string to destinations string. At most n bytes will be copied. The destination string is guaranteed to be null terminated. More... | |
| int | sprintf_s (char *str, size_t n, const char *format,...) |
| Format print to string up to n-1 characters. String is guaranteed to be null terminated. More... | |
Memory allocation and deallocation declarations.
General purpose dynamic memory allocate and deallocate declarations and defines. None of the calls will fail, unless fatally for the entire program. Modeled on C++ new() and delete() operators.
—
Definition in file new.h.
| #define NEW | ( | T | ) | (T *)new(sizeof(T)) |
Allocate new type.
| T | Data type. |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
Definition at line 49 of file new.h.
Referenced by AddNewBody(), ConfigDbIterNew(), ConfigDbNew(), ConfigSectionIterNew(), ConfigSectionNew(), DListVoidAppend(), DListVoidInsert(), DListVoidNew(), DListVoidPrepend(), hash_table_create(), hnode_create(), NewZooAnimal(), OptsNew(), SearchPathIterNew(), SimpleBufNew(), SimpleBufNewWithBuf(), SocketNew(), SockSetNew(), and UriParseNew().
| #define NEWSTR | ( | len | ) | (char *)new( sizeof(char)*((size_t)((len)+1)) ) |
Allocate new string buffer of length len+1.
| len | Length of string buffer less null-termination character. |
| Bad Allocation | Program is terminated with exit code EC_ERROR. |
Definition at line 64 of file new.h.
Referenced by new_strdup(), new_strndup(), NewJoinedPath(), NewNormPath(), NewPrettyBuf(), NewSearchPathCanonicalized(), NewSearchPathExpanded(), SearchPathIterFirst(), SearchPathIterNext(), SocketAddrNameInet(), SocketAddrNameUnix(), SocketThisHostName(), and UriStrNew().
| INLINE_IN_H void delete | ( | void * | p | ) |
delete() "operator"
Frees previously allocated memory. NULL pointer produce no action.
| p | Pointer to memory. |
Definition at line 77 of file new.h.
References C_DECLS_BEGIN, C_DECLS_END, new_memdup(), new_overs(), new_strdup(), new_strndup(), NULL, sprintf_s(), and strcpy_s().
| 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().
| int sprintf_s | ( | char * | str, |
| size_t | n, | ||
| const char * | format, | ||
| ... | |||
| ) |
Format print to string up to n-1 characters. String is guaranteed to be null terminated.
| str | Destination string buffer. |
| n | Size of string buffer. |
| format | Standard printf formatting string. |
| ... | Variable argument list. |
Definition at line 83 of file win.c.
Referenced by delete().
| char* strcpy_s | ( | char * | dest, |
| size_t | n, | ||
| const char * | src | ||
| ) |
Copy source string to destinations string. At most n bytes will be copied. The destination string is guaranteed to be null terminated.
| dest | Pointer to destination string. |
| n | Maximum number of bytes to copy. |
| src | Pointer to source string. |
Definition at line 65 of file win.c.
Referenced by delete().