29 #ifndef UCX_ALLOCATOR_H |
29 #ifndef UCX_ALLOCATOR_H |
30 #define UCX_ALLOCATOR_H |
30 #define UCX_ALLOCATOR_H |
31 |
31 |
32 #include <stdlib.h> |
32 #include <stdlib.h> |
33 |
33 |
34 /* LOW LEVEL API */ |
34 typedef void *(*cx_malloc_func)(void *data, size_t n); |
35 |
35 |
36 typedef void* cx_allocator; |
36 typedef void *(*cx_realloc_func)(void *data, void *mem, size_t n); |
37 typedef void*(*cx_malloc_func)(cx_allocator a, size_t n); |
|
38 typedef void*(*cx_realloc_func)(cx_allocator a, void* mem, size_t n); |
|
39 typedef void*(*cx_calloc_func)(cx_allocator a, size_t nelem, size_t n); |
|
40 typedef void(*cx_free_func)(cx_allocator a, void* mem); |
|
41 |
37 |
42 void* cx_malloc_stdlib(cx_allocator a, size_t n); |
38 typedef void *(*cx_calloc_func)(void *data, size_t nelem, size_t n); |
43 void* cx_realloc_stdlib(cx_allocator a, void* mem, size_t n); |
39 |
44 void* cx_calloc_stdlib(cx_allocator a, size_t nelem, size_t n); |
40 typedef void(*cx_free_func)(void *data, void *mem); |
45 void cx_free_stdlib(cx_allocator a, void* mem); |
|
46 |
41 |
47 typedef struct { |
42 typedef struct { |
48 cx_malloc_func malloc; |
43 cx_malloc_func malloc; |
49 cx_realloc_func realloc; |
44 cx_realloc_func realloc; |
50 cx_calloc_func calloc; |
45 cx_calloc_func calloc; |
51 cx_free_func free; |
46 cx_free_func free; |
52 } cx_allocator_class; |
47 } cx_allocator_class; |
53 |
48 |
54 extern cx_allocator_class cx_default_allocator_class; |
49 extern cx_allocator_class cx_default_allocator_class; |
55 |
50 |
56 /* HIGH LEVEL API */ |
|
57 |
|
58 struct cx_allocator_s { |
51 struct cx_allocator_s { |
59 cx_allocator_class *cl; |
52 cx_allocator_class *cl; |
60 cx_allocator data; |
53 void *data; |
61 }; |
54 }; |
62 typedef struct cx_allocator_s* CxAllocator; |
55 typedef struct cx_allocator_s *CxAllocator; |
63 |
56 |
64 extern CxAllocator cxDefaultAllocator; |
57 extern CxAllocator cxDefaultAllocator; |
65 |
58 |
66 void* cxMalloc(CxAllocator allocator, size_t n); |
59 void *cxMalloc(CxAllocator allocator, size_t n); |
67 void* cxRealloc(CxAllocator allocator, void* mem, size_t n); |
60 |
68 void* cxCalloc(CxAllocator allocator, size_t nelem, size_t n); |
61 void *cxRealloc(CxAllocator allocator, void *mem, size_t n); |
69 void cxFree(CxAllocator allocator, void* mem); |
62 |
|
63 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n); |
|
64 |
|
65 void cxFree(CxAllocator allocator, void *mem); |
70 |
66 |
71 #endif /* UCX_ALLOCATOR_H */ |
67 #endif /* UCX_ALLOCATOR_H */ |