This provides an example of how to implement a memory handler. The code below is actually the internal implementation used for the default memory handler (which is used when you pass NULL
for the memory handler).
#include <stdlib.h>
static void *eaarlio_memory_malloc(
struct eaarlio_memory *
self,
size_t size)
{
(void)self;
return malloc(size);
}
static void eaarlio_memory_free(
struct eaarlio_memory *
self,
void *ptr)
{
(void)self;
free(ptr);
}
void *ptr,
size_t size)
{
(void)self;
return realloc(ptr, size);
}
size_t nmemb,
size_t size)
{
(void)self;
return calloc(nmemb, size);
}
struct eaarlio_memory eaarlio_memory_default = { eaarlio_memory_malloc,
eaarlio_memory_free, eaarlio_memory_realloc, eaarlio_memory_calloc, NULL };