diff -r 8c0421ccbb58 -r 80c31ebd66c1 src/cx/allocator.h --- a/src/cx/allocator.h Sun Feb 07 15:35:52 2021 +0100 +++ b/src/cx/allocator.h Sun Feb 07 16:24:41 2021 +0100 @@ -31,6 +31,8 @@ #include +/* LOW LEVEL API */ + typedef void* cx_allocator; typedef void*(*cx_malloc_func)(cx_allocator a, size_t n); typedef void*(*cx_realloc_func)(cx_allocator a, void* mem, size_t n); @@ -42,20 +44,26 @@ void* cx_calloc_stdlib(cx_allocator a, size_t nelem, size_t n); void cx_free_stdlib(cx_allocator a, void* mem); -struct cx_allocator_s { +struct cx_allocator_class { cx_malloc_func malloc; cx_realloc_func realloc; cx_calloc_func calloc; cx_free_func free; +}; + +/* HIGH LEVEL API */ + +struct cx_allocator_s { + struct cx_allocator_class allocatorClass; void* data; }; typedef struct cx_allocator_s* CxAllocator; extern CxAllocator cxDefaultAllocator; -#define cxMalloc(a, n) (a)->malloc((a), n) -#define cxRealloc(a, mem, n) (a)->realloc((a), mem, n) -#define cxCalloc(a, nelem, n) (a)->calloc((a), nelem, n) -#define cxFree(a, mem) (a)->free((a), mem) +void* cxMalloc(CxAllocator allocator, size_t n); +void* cxRealloc(CxAllocator allocator, void* mem, size_t n); +void* cxCalloc(CxAllocator allocator, size_t nelem, size_t n); +void cxFree(CxAllocator allocator, void* mem); #endif /* UCX_ALLOCATOR_H */