Macros for use in memory allocation and deallocation. These macros wrap the standard malloc, calloc, realloc and free functions and should always be preferred over these functions.
Also see Memory Allocation Example.
S_MALLOC | Allocate memory to a pointer, given a defined type. |
S_MALLOC_SIZE | Allocate memory to a pointer, given a size in bytes. |
S_CALLOC | Allocate memory to a pointer and set it to zero, given a defined type. |
S_CALLOC_SIZE | Allocate memory to a pointer and set it to zero, given a size in bytes. |
S_REALLOC | Change the size of the memory block, given a defined type. |
S_REALLOC_SIZE | Change the size of the memory block, given a size in bytes. |
S_FREE | Free previously allocated memory. |
Allocate memory to a pointer, given a defined type.
Allocate NMEMB number of TYPE data type and return a pointer to the allocated memory.
Parameters: |
|
---|---|
Return: | Pointer to the allocated memory or NULL if failed. |
Note: | If (sizeof(TYPE) * NMEMB) = 0 then NULL is returned. |
Allocate memory to a pointer and set it to zero, given a defined type.
Allocate NMEMB number of TYPE data type and returns a pointer to the allocated memory.
Parameters: |
|
---|---|
Return: | Pointer to the allocated memory (set to zero) or NULL if failed. |
Note: | If (sizeof(TYPE) * NMEMB) = 0 then NULL is returned. |
Allocate memory to a pointer and set it to zero, given a size in bytes.
Allocate SIZE bytes and returns a pointer to the allocated memory.
Parameters: |
|
---|---|
Return: | Pointer to the allocated memory (set to zero) or NULL if failed. |
Note: | If SIZE = 0 then NULL is returned. |
Change the size of the memory block, given a defined type.
Change the size of the memory block pointed to by P to NMEMB number of TYPE data type.
Parameters: |
|
---|---|
Return: | Pointer to the allocated memory or NULL if failed. |
Note: | If (sizeof(TYPE) * NMEMB) = 0 then P is freed and NULL returned. If memory allocation failed then P is freed. |
Change the size of the memory block, given a size in bytes.
Changes the size of the memory block pointed to by P to SIZE bytes.
Parameters: |
|
---|---|
Return: | Pointer to the allocated memory or NULL if failed. |
Note: | If SIZE = 0 then P is freed and NULL returned. If memory allocation failed then P is freed. |