src/cx/allocator.h

changeset 394
80c31ebd66c1
parent 393
8c0421ccbb58
child 396
3539dd99ab92
     1.1 --- a/src/cx/allocator.h	Sun Feb 07 15:35:52 2021 +0100
     1.2 +++ b/src/cx/allocator.h	Sun Feb 07 16:24:41 2021 +0100
     1.3 @@ -31,6 +31,8 @@
     1.4  
     1.5  #include <stdlib.h>
     1.6  
     1.7 +/* LOW LEVEL API */
     1.8 +
     1.9  typedef void* cx_allocator;
    1.10  typedef void*(*cx_malloc_func)(cx_allocator a, size_t n);
    1.11  typedef void*(*cx_realloc_func)(cx_allocator a, void* mem, size_t n);
    1.12 @@ -42,20 +44,26 @@
    1.13  void* cx_calloc_stdlib(cx_allocator a, size_t nelem, size_t n);
    1.14  void cx_free_stdlib(cx_allocator a, void* mem);
    1.15  
    1.16 -struct cx_allocator_s {
    1.17 +struct cx_allocator_class {
    1.18      cx_malloc_func malloc;
    1.19      cx_realloc_func realloc;
    1.20      cx_calloc_func calloc;
    1.21      cx_free_func free;
    1.22 +};
    1.23 +
    1.24 +/* HIGH LEVEL API */
    1.25 +
    1.26 +struct cx_allocator_s {
    1.27 +    struct cx_allocator_class allocatorClass;
    1.28      void* data;
    1.29  };
    1.30  typedef struct cx_allocator_s* CxAllocator;
    1.31  
    1.32  extern CxAllocator cxDefaultAllocator;
    1.33  
    1.34 -#define cxMalloc(a, n) (a)->malloc((a), n)
    1.35 -#define cxRealloc(a, mem, n) (a)->realloc((a), mem, n)
    1.36 -#define cxCalloc(a, nelem, n) (a)->calloc((a), nelem, n)
    1.37 -#define cxFree(a, mem) (a)->free((a), mem)
    1.38 +void* cxMalloc(CxAllocator allocator, size_t n);
    1.39 +void* cxRealloc(CxAllocator allocator, void* mem, size_t n);
    1.40 +void* cxCalloc(CxAllocator allocator, size_t nelem, size_t n);
    1.41 +void cxFree(CxAllocator allocator, void* mem);
    1.42  
    1.43  #endif /* UCX_ALLOCATOR_H */

mercurial