37 lines
1.3 KiB
Text
37 lines
1.3 KiB
Text
-----------------------------------
|
|
xalloc - safe memory allocation
|
|
-----------------------------------
|
|
|
|
this module implements malloc and friends + some extensions.
|
|
if __DEBUG__ symbol is defined. the functions will provide extended
|
|
debug logic and kills the program (passing 0 as size to malloc for example).
|
|
|
|
the funtions will at all times kill the program if memory can't be allocated for
|
|
some reason, this makes the need for client-code to check for null pointers returned
|
|
by these functions redundant.
|
|
|
|
-- functions
|
|
|
|
xmalloc():
|
|
|
|
just like malloc, this function allocates a block of memory of 'size' bytes.
|
|
if compiled with the __DEBUG__ symbol, the function will not allow zero size
|
|
|
|
xmallocz():
|
|
|
|
exactly like xmalloc but will initialize the block with zero.
|
|
|
|
xrealloc():
|
|
|
|
reallocates a previous allocated block of memory to 'size' bytes.
|
|
if compiled with the __DEBUG__ symbol, the function will not allow zero size
|
|
|
|
xstrdup():
|
|
|
|
allocates and copies the string 's' to a new memory location and returns it to the user.
|
|
if compiled with the __DEBUG__ symbol, the function will not allow 's' to be a NULL pointer
|
|
|
|
xfree():
|
|
|
|
free's a previous allocated block pointed by 'ptr' that is allocated by xmalloc/malloc.
|
|
if compiled with the __DEBUG__ symbol, the function will not allow 'ptr' to be a NULL pointer
|