Deallocates a memory block.
Note: malloc allocates physical memory to the current process's Vseg as required. free never physically releases memory allocated by malloc.
For alternative memory management methods, see heap object management.
#include <stdlib.h> #include <malloc.h> void free (void *memblock); void _free_internal (void *memblock);
The number of bytes freed is the number of bytes specified when the block was allocated, or reallocated, in the case of realloc. After the call, the freed block is available for allocation.
_free_internal behaves identically to free, use it to implement your own debug version of free.
Calling free() on an invalid pointer is a run-time error. The error is reported to the user via the signal interface. To install your own SIGFREE handler:
#include <signal.h>
void mysigfree(int signal) {
printf(“mysigfree: %d\n”, signal);
}
signal(SIGFREE, mysigfree);
To ignore the SIGFREE signal:
signal(SIGFREE, SIG_IGN);
You may write your own free stub which validates the pointer and optionally reports the error.
void free(void *p) {
if (heap_validate_buffer(p) == -1)
// do something ;
else
_free_internal(p);
}
None.
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/stdlib.h | stdlib.h malloc.h |
clib.lib |