42 lines
1.5 KiB
Text
42 lines
1.5 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's.
|
|
|
|
`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
|
|
|
|
`xmemdup()`::
|
|
|
|
Allocates and copies `len` bytes from `ptr` to a new memory location and returns it to the user. +
|
|
If compiled with the `__DEBUG__` symbol, the function will not allow 'ptr' to be a `NULL` pointer
|
|
|
|
`xfree()`::
|
|
|
|
Free's a previous allocated block (pointed to 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
|