There are basic memory handling wrappers around the standard C library memory handling routines. The key difference is, that the ooc memory handling throws exceptions in case of a system failure, and performs some tasks that are necessary for multi-threaded or reentrant programming.
You can allocate memory with the following routines:
void * ooc_malloc( size_t size );
The same to the standard
malloc, except that throws an exception on failure, thus never returns
void * ooc_calloc( size_t num, size_t size );
calloc, except that throws an exception on failure, thus never returns
void * ooc_realloc( void *ptr, size_t size );
realloc, except that throws an exception on failure, thus never returns
void * ooc_memdup( const void * ptr, size_t size );
memcpy, and throws an exception on failure, thus never returns
Deallocate the memory with one of the following methods:
void ooc_free( void * mem );
Frees a memory block allocated with one of the above allocation codes. Never failes,
mem can be
void ooc_free_and_null( void ** mem_ptr );
mem_ptrcan point to a NULL pointer.
Always use this, if your class has a memory pointer as a class member, for example in a class destructor!
Important! ooc is thread safe only if the underlying standard C library (malloc, calloc, realloc, setjmp/longjmp) is thread-safe too!
The thread safety of ooc does not mean that your code will be thread safe automatically! You must take care about the proper thread-safe implementation of your classes!
ooc_finalize_all()functions are not thread safe! It is advisable calling
ooc_init_class()from the main thread before the fork and
ooc_finalize_all()after the join.