ne_malloc

Langue: en

Version: 25 February 2009 (fedora - 05/07/09)

Section: 3 (Bibliothèques de fonctions)

ne_malloc, ne_calloc, ne_realloc, ne_strdup, ne_strndup, ne_oom_callback - memory allocation wrappers

Synopsis

 #include <ne_alloc.h>
 
void *ne_malloc(size_t size);
void *ne_calloc(size_t size);
void *ne_realloc(void *size, size_t len);
char *ne_strdup(const char *s);
char *ne_strndup(const char *s, size_t size);
void ne_oom_callback(void (*callback)(void));
 

Description

The functions ne_malloc, ne_calloc, ne_realloc, ne_strdup and ne_strdnup provide wrappers for the equivalent functions in the standard C library. The wrappers provide the extra guarantee that if the C library equivalent returns FCNULLF[] when no memory is available, an optional callback will be called, and the library will then call abort().

ne_oom_callback registers a callback which will be invoked if an out of memory error is detected.

Notes

If the operating system uses optimistic memory allocation, the C library memory allocation routines will not return FCNULLF[], so it is not possible to gracefully handle memory allocation failures.

Author

Joe Orton <neon@lists.manyfish.co.uk>

Author.