#include <stddef.h>
Go to the source code of this file.
Functions | |
void * | dnxMalloc (size_t sz, char *file, int line) |
Allocate and track a new heap memory block. | |
void * | dnxCalloc (size_t n, size_t sz, char *file, int line) |
Allocate, zero and track a new heap memory block. | |
void * | dnxRealloc (void *p, size_t sz, char *file, int line) |
Reallocate (and track) an existing heap memory block. | |
char * | dnxStrdup (char *str, char *file, int line) |
Duplicate and track a string from the heap. | |
void | dnxFree (void *p) |
Free and previously allocated (and tracked) heap memory block. | |
int | dnxCheckHeap (void) |
Check the heap and display any unfreed blocks on the global list. |
Definition in file dnxHeap.h.
void* dnxCalloc | ( | size_t | n, | |
size_t | sz, | |||
char * | file, | |||
int | line | |||
) |
Allocate, zero and track a new heap memory block.
Calloc is sort of a strange bird - it should be the same as malloc with the addition of zeroing the block before returning, but K&R must have decided that the X x Y block allocation strategry had some value for heap blocks that need to be cleared...
[in] | n | - the number of blocks of sz bytes to be allocated. |
[in] | sz | - the size of each of the n blocks to be allocated. |
[in] | file | - the file name from where this function was called. |
[in] | line | - the line number from where this function was called. |
Definition at line 253 of file dnxHeap.c.
References dnxMalloc().
int dnxCheckHeap | ( | void | ) |
Check the heap and display any unfreed blocks on the global list.
Definition at line 334 of file dnxHeap.c.
References blkcnt, check_block(), dnxDebug(), dump_block(), list_lock, and overhead_::next.
void dnxFree | ( | void * | p | ) |
Free and previously allocated (and tracked) heap memory block.
Note that there are serveral good programming-practice reasons to call free with a p
argument value of null. This debug routine allows it.
[in] | p | - a pointer to the debug heap block to be freed. |
Definition at line 311 of file dnxHeap.c.
References check_block(), dnxDebug(), overhead_::file, and unlink_block().
Referenced by dnxRealloc().
void* dnxMalloc | ( | size_t | sz, | |
char * | file, | |||
int | line | |||
) |
Allocate and track a new heap memory block.
malloc allows sz to be zero, in which case, it returns NULL. But there's really no reason to call malloc with a zero value unless the programmer made a mistake, so this routine asserts that sz
is non-zero.
[in] | sz | - the size in bytes of the block to be allocated. |
[in] | file | - the file name from where this function was called. |
[in] | line | - the line number from where this function was called. |
Definition at line 219 of file dnxHeap.c.
References overhead_::actualsz, ALIGNED, ALIGNSZ, ALLOCED, dnxDebug(), overhead_::file, overhead_::line, link_block(), overhead_::next, PICKET1, overhead_::picket1, PICKET2, overhead_::picket2, PICKET3, PICKETSZ, and overhead_::reqsz.
Referenced by dnxCalloc(), dnxRealloc(), and dnxStrdup().
void* dnxRealloc | ( | void * | p, | |
size_t | sz, | |||
char * | file, | |||
int | line | |||
) |
Reallocate (and track) an existing heap memory block.
Realloc - the all-in-one heap management function. If p
is NULL, realloc acts like malloc, if sz
is zero, realloc acts like free.
Since there's no reason except programmer error that would have both p
and sz
be zero at the same time, this routine asserts one or the other is non-zero.
[in] | p | - a pointer to the block to be reallocated/resized. |
[in] | sz | - the new size of the block. |
[in] | file | - the file name from where this function was called. |
[in] | line | - the line number from where this function was called. |
Definition at line 270 of file dnxHeap.c.
References dnxFree(), dnxMalloc(), and overhead_::reqsz.
char* dnxStrdup | ( | char * | str, | |
char * | file, | |||
int | line | |||
) |
Duplicate and track a string from the heap.
[in] | str | - a pointer to the zero-terminated string to be duplicated. |
[in] | file | - the file name from where this function was called. |
[in] | line | - the line number from where this function was called. |
Definition at line 292 of file dnxHeap.c.
References dnxMalloc().