manpagez: man pages & more
info cln
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.4 Customizing the memory allocator

Every memory allocation of CLN is done through the function pointer malloc_hook. Freeing of this memory is done through the function pointer free_hook. The default versions of these functions, provided in the library, call malloc and free and check the malloc result against NULL. If you want to provide another memory allocator, you need to define the variables malloc_hook and free_hook yourself, like this:

#include <cln/malloc.h>
namespace cln {
        void* (*malloc_hook) (size_t size) = …;
        void (*free_hook) (void* ptr)      = …;
}

The cl_malloc_hook function must not return a NULL pointer.

It is not possible to change the memory allocator at runtime, because it is already called at program startup by the constructors of some global variables.


This document was generated on August 27, 2013 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.