38#ifndef __AllocatorIntf_h
39#define __AllocatorIntf_h
41#include <TargConfig.h>
56typedef void* (*AllocatorIntf_Malloc)(
struct AllocatorIntf* o,
size_t* size);
63typedef void* (*AllocatorIntf_Realloc)(
69typedef void (*AllocatorIntf_Free)(
struct AllocatorIntf* o,
void* memblock);
96 AllocatorIntf_Free
free);
109 void*
malloc(
size_t* size);
117 void*
realloc(
void* p,
size_t* size);
124 AllocatorIntf_Malloc mallocCB;
125 AllocatorIntf_Realloc reallocCB;
126 AllocatorIntf_Free freeCB;
129#define AllocatorIntf_constructor(o, m, r, f) do { \
135#define AllocatorIntf_malloc(o, size) (o)->mallocCB(o, size)
136#define AllocatorIntf_realloc(o, memblock, size) \
137 ((o)->reallocCB ? (o)->reallocCB(o,memblock,size) : 0)
138#define AllocatorIntf_free(o, memblock) (o)->freeCB(o,memblock)
148BA_API
char* baStrdup2(
struct AllocatorIntf* a,
const char* str);
152inline AllocatorIntf::AllocatorIntf(AllocatorIntf_Malloc malloc,
153 AllocatorIntf_Realloc realloc,
154 AllocatorIntf_Free free) {
157 return AllocatorIntf_getDefault(); }
159 return AllocatorIntf_malloc(
this, size); }
161 return AllocatorIntf_realloc(
this, memblock, size); }
163 AllocatorIntf_free(
this, memblock); }
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
void * realloc(void *p, size_t *size)
Returns pointer to newly-allocated space for an object of size "size", initialized,...
Definition: AllocatorIntf.h:160
void * malloc(size_t *size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
Definition: AllocatorIntf.h:158
void free(void *p)
Deallocates space to which it points.
Definition: AllocatorIntf.h:162
static AllocatorIntf * getDefault(void)
Returns a pointer to a predefined AllocatorIntf class.
Definition: AllocatorIntf.h:156