Defines | |
| #define | GGZ_MEM_DEBUG "ggz_mem" |
| Debugging type for memory debugging. | |
| #define | ggz_malloc(size) _ggz_malloc(size, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
| Macro for memory allocation. | |
| #define | ggz_realloc(mem, size) _ggz_realloc(mem, size, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
| Macro for resizing previously allocated memory. | |
| #define | ggz_free(mem) _ggz_free(mem, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
| Macro for freeing memory previously allocated. | |
| #define | ggz_strdup(string) _ggz_strdup(string, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
| Macro for duplicating string. | |
Functions | |
| void * | _ggz_malloc (const size_t size, const char *tag, int line) |
| Function to actually perform memory allocation. | |
| void * | _ggz_realloc (const void *ptr, const size_t size, const char *tag, int line) ggz__attribute((warn_unused_result)) |
| Function to perform memory reallocation. | |
| int | _ggz_free (const void *ptr, const char *tag, int line) |
| Function to free allocated memory. | |
| char * | _ggz_strdup (const char *ptr, const char *tag, int line) ggz__attribute((warn_unused_result)) |
| Function to copy a string. | |
| char * | ggz_strncpy (char *dst, const char *src, size_t n) |
| Safe version of strncpy. | |
| int | ggz_memory_check (void) |
| Check memory allocated against memory freed and display any discrepancies. | |
They keep track of memory allocated by storing the name of the function and file in which they were called.
You can then call ggz_memory_check() to make sure all allocated memory has been freed. Note that you will need to enable MEMORY debugging to see this.
| #define GGZ_MEM_DEBUG "ggz_mem" |
| #define ggz_malloc | ( | size | ) | _ggz_malloc(size, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
Macro for memory allocation.
| size | the size of memory to allocate, in bytes |
| #define ggz_realloc | ( | mem, | |||
| size | ) | _ggz_realloc(mem, size, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
Macro for resizing previously allocated memory.
| mem | pointer to memory to reallocate | |
| size | new size requested, in bytes |
| #define ggz_free | ( | mem | ) | _ggz_free(mem, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
Macro for freeing memory previously allocated.
| mem | pointer to allocated memory |
| #define ggz_strdup | ( | string | ) | _ggz_strdup(string, _GGZFUNCTION_ " in " __FILE__, __LINE__) |
Macro for duplicating string.
| string | string to duplicate |
| void* _ggz_malloc | ( | const size_t | size, | |
| const char * | tag, | |||
| int | line | |||
| ) |
Function to actually perform memory allocation.
Don't call this directly. Instead, call ggz_malloc().
| size | size of memory to allocate, in bytes | |
| tag | string describing the calling function | |
| line | linenumber |
| void* _ggz_realloc | ( | const void * | ptr, | |
| const size_t | size, | |||
| const char * | tag, | |||
| int | line | |||
| ) |
Function to perform memory reallocation.
Don't call this directly. Instead, call ggz_realloc().
| ptr | pointer to memory to reallocate | |
| size | new size, in bytes | |
| tag | string describing the calling function | |
| line | linenumber |
| int _ggz_free | ( | const void * | ptr, | |
| const char * | tag, | |||
| int | line | |||
| ) |
Function to free allocated memory.
Don't call this directly. Instead, call ggz_free().
| ptr | pointer to memory | |
| tag | string describing the calling function | |
| line | linenumber |
| char* _ggz_strdup | ( | const char * | ptr, | |
| const char * | tag, | |||
| int | line | |||
| ) |
Function to copy a string.
Don't call this directly. Instead, call ggz_strdup().
| ptr | string to duplicate | |
| tag | string describing the calling function | |
| line | linenumber |
| char* ggz_strncpy | ( | char * | dst, | |
| const char * | src, | |||
| size_t | n | |||
| ) |
Safe version of strncpy.
This function will behave like strncpy(), except that the result string is always guaranteed to be NULL-terminated. This matches the behaviour of snprintf() and leads to generally safer code.
| dst | destination string buffer | |
| src | source string | |
| n | number of bytes to copy, should be less than buffer size |
| int ggz_memory_check | ( | void | ) |
Check memory allocated against memory freed and display any discrepancies.
1.5.1