oop_malloc(), oop_free()
#include <oop.h>
extern void *(*oop_malloc)(size_t len); /* Allocate memory. */
extern void *(*oop_realloc*)(void *ptr,size_t len); /* Resize memory. */
extern void (*oop_free)(void *ptr); /* Free allocated memory. */
Arguments.
- size_t len
- Size, in bytes, of the memory block to allocate.
- void *ptr
- Pointer to memory block to free or reallocate.
Description.
These are global function pointers, initialized by default to the standard C
library functions malloc, realloc, and free.
Applications using liboop may reset these pointers to allocation and
deallocation routines with a compatible interface; libraries should use
these function pointers wherever possible to allocate and release memory.
These pointers are normally set before calling any liboop code; if they
are changed during operation, the new oop_free and
oop_realloc functions should be
capable of handling memory obtained with the old oop_malloc.
- oop_malloc
- This function allocates a block of memory of size len and returns
a pointer to the start of the block. If allocation fails, NULL is returned.
- oop_realloc*
- This function resizes a block of memory at ptr to have the new
length len. If ptr is NULL, fresh memory is allocated.
If len is zero, memory is freed and NULL is returned.
If ptr is NULL and len is zero, nothing is done and NULL
is returned. If reallocation fails, NULL is returned.
- oop_free
- This function releases a block of memory, designated by ptr,
previously allocated by oop_malloc. Once released, the memory may
be immediately overwritten, and/or reused by subsequent calls to
oop_malloc.
* Compatibility note: oop_realloc
is only available in version 0.7 or newer.
liboop reference