5.3 Custom Allocators

In some circumstances it can be desirable to force all allocations through a set of ‘custom’ allocators. These are defined as a fz_alloc_context structure whose address is passed in to fz_new_context. This structure must exist for the life time of the returned fz_context (and any clones).

typedef struct 
{ 
   void *user; 
   void *(*malloc)(void *, size_t); 
   void *(*realloc)(void *, void *, size_t); 
   void (*free)(void *, void *); 
} fz_alloc_context;

The malloc, realloc and free function pointers have essentially the same semantics as the standard malloc, realloc and free standard functions, with the exception that they take an additional initial argument - that of the user value specified in the fz_alloc_context.