diff options
Diffstat (limited to 'lib/memory.c')
-rw-r--r-- | lib/memory.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/memory.c b/lib/memory.c index d96ff21d..10e107a3 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -115,6 +115,12 @@ zerror (const char *fname, int type, size_t size) /*------------------------------------------------------------------------------ * Memory allocation. + * + * Allocate memory of a given size, to be tracked by a given type. + * + * Returns: pointer to usable memory. + * + * NB: If memory cannot be allocated, aborts execution. */ void * zmalloc (enum MTYPE mtype, size_t size MEMORY_TRACKER_NAME) @@ -173,7 +179,15 @@ zcalloc (enum MTYPE mtype, size_t size MEMORY_TRACKER_NAME) /*------------------------------------------------------------------------------ * Memory reallocation. * - * NB: just like real realloc(), is same as malloc() if ptr == NULL. + * Given a pointer returned by zmalloc()/zcalloc()/zrealloc(), extend or + * contract the allocation to the given size -- retaining current type. + * The type given MUST be the original type. + * + * Given a NULL, allocate memory as zmalloc(). + * + * Returns: pointer to usable memory. + * + * NB: If memory cannot be allocated, aborts execution. */ void * zrealloc (enum MTYPE mtype, void *ptr, size_t size MEMORY_TRACKER_NAME) @@ -203,7 +217,10 @@ zrealloc (enum MTYPE mtype, void *ptr, size_t size MEMORY_TRACKER_NAME) /*------------------------------------------------------------------------------ * Memory free. * - * NB: just like real free(), does nothing if ptr == NULL. + * Free memory allocated by zmalloc()/zcalloc()/zrealloc()/zstrdup(). + * The type given MUST be the original type. + * + * Does nothing if the given pointer is NULL. */ void zfree (enum MTYPE mtype, void *ptr) @@ -226,6 +243,10 @@ zfree (enum MTYPE mtype, void *ptr) /*------------------------------------------------------------------------------ * String duplication. + * + * Memory is allocated as zmalloc() and must later be freed by zfree(). + * + * NB: If memory cannot be allocated, aborts execution. */ char * zstrdup (enum MTYPE mtype, const char *str MEMORY_TRACKER_NAME) |