dnxHeap.h File Reference

#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.


Function Documentation

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...

Parameters:
[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.
Returns:
A pointer to the new memory block, or NULL on allocation failure.

Definition at line 253 of file dnxHeap.c.

int dnxCheckHeap ( void   ) 

Check the heap and display any unfreed blocks on the global list.

Returns:
Zero on success, or a non-zero error code.

Definition at line 334 of file dnxHeap.c.

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.

Parameters:
[in] p - a pointer to the debug heap block to be freed.

Definition at line 311 of file dnxHeap.c.

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.

Parameters:
[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.
Returns:
A pointer to the new memory block, or NULL on allocation failure.

Definition at line 219 of file dnxHeap.c.

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.

Parameters:
[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.
Returns:
A pointer to the new memory block, or NULL on allocation failure.

Definition at line 270 of file dnxHeap.c.

char* dnxStrdup ( char *  str,
char *  file,
int  line 
)

Duplicate and track a string from the heap.

Parameters:
[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.
Returns:
A pointer to the new memory block, or NULL on allocation failure.

Definition at line 292 of file dnxHeap.c.


Generated on Tue Apr 13 15:15:29 2010 for DNX by  doxygen 1.5.6