|
EzC
|
Memory-related macros, such as allocation and array length getters. More...
Go to the source code of this file.
Macros | |
| #define | EZC_LENGTH(array) (sizeof(array)/sizeof(array[0])) |
| Get the length of an array. More... | |
| #define | EZC_NEW(ptr) ((ptr) = malloc(sizeof *(ptr))) |
| Allocate memory based on the size of the given pointer. More... | |
| #define | EZC_NEW0(ptr) ((ptr) = calloc(1, sizeof *(ptr))) |
| Allocate memory based on the size of the given pointer while also zero-initializing it. More... | |
| #define | EZC_NEWN(ptr, n) ((ptr) = calloc((n), sizeof *(ptr))) |
| Allocate array and zero-initialize it. More... | |
| #define | EZC_FREE(ptr, ...) |
| Free memory and avoid dangling pointers. More... | |
Memory-related macros, such as allocation and array length getters.
| #define EZC_FREE | ( | ptr, | |
| ... | |||
| ) |
Free memory and avoid dangling pointers.
This macro does both the free and ptr = 0 for you! Simply use EZC_FREE(ptr);.
| ptr | Pointer that you want set to zero and whose memory it was pointing to you want freed. |
| ... | Optional additional pointers you want to be freed. |
| #define EZC_LENGTH | ( | array | ) | (sizeof(array)/sizeof(array[0])) |
Get the length of an array.
This works via the sizeof(array)/sizeof(array[0]) technique.
| array | Pointer to an array. |
| #define EZC_NEW | ( | ptr | ) | ((ptr) = malloc(sizeof *(ptr))) |
Allocate memory based on the size of the given pointer.
Does the work of calling sizeof for you! This macro does the ptr = ... for you, all you need to do is EZC_NEW(ptr);.
| ptr | Pointer to which you want memory allocated. |
| #define EZC_NEW0 | ( | ptr | ) | ((ptr) = calloc(1, sizeof *(ptr))) |
Allocate memory based on the size of the given pointer while also zero-initializing it.
EZC_NEW details documentation also applies to EZC_NEW0.
| ptr | Pointer to which you want memory allocated. |
| #define EZC_NEWN | ( | ptr, | |
| n | |||
| ) | ((ptr) = calloc((n), sizeof *(ptr))) |
Allocate array and zero-initialize it.
EZC_NEW details documentation also applies to EZC_NEWN.
| ptr | Pointer to which you want memory allocated. |
1.8.15