src/allocator.c

changeset 500
eb9e7bd40a8e
parent 452
a10c3e127050
child 508
8aea65ae1eaf
equal deleted inserted replaced
499:3dc9075df822 500:eb9e7bd40a8e
59 59
60 struct cx_allocator_s cx_default_allocator = { 60 struct cx_allocator_s cx_default_allocator = {
61 &cx_default_allocator_class, 61 &cx_default_allocator_class,
62 NULL 62 NULL
63 }; 63 };
64 CxAllocator cxDefaultAllocator = &cx_default_allocator; 64 CxAllocator *cxDefaultAllocator = &cx_default_allocator;
65 65
66 /* IMPLEMENTATION OF HIGH LEVEL API */ 66 /* IMPLEMENTATION OF HIGH LEVEL API */
67 67
68 void *cxMalloc(CxAllocator allocator, size_t n) { 68 void *cxMalloc(
69 CxAllocator *allocator,
70 size_t n
71 ) {
69 return allocator->cl->malloc(allocator->data, n); 72 return allocator->cl->malloc(allocator->data, n);
70 } 73 }
71 74
72 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) { 75 void *cxRealloc(
76 CxAllocator *allocator,
77 void *mem,
78 size_t n
79 ) {
73 return allocator->cl->realloc(allocator->data, mem, n); 80 return allocator->cl->realloc(allocator->data, mem, n);
74 } 81 }
75 82
76 int cxReallocate(CxAllocator allocator, void **mem, size_t n) { 83 int cxReallocate(
84 CxAllocator *allocator,
85 void **mem,
86 size_t n
87 ) {
77 void *nmem = allocator->cl->realloc(allocator->data, *mem, n); 88 void *nmem = allocator->cl->realloc(allocator->data, *mem, n);
78 if (nmem == NULL) { 89 if (nmem == NULL) {
79 return 1; 90 return 1;
80 } else { 91 } else {
81 *mem = nmem; 92 *mem = nmem;
82 return 0; 93 return 0;
83 } 94 }
84 } 95 }
85 96
86 void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) { 97 void *cxCalloc(
98 CxAllocator *allocator,
99 size_t nelem,
100 size_t n
101 ) {
87 return allocator->cl->calloc(allocator->data, nelem, n); 102 return allocator->cl->calloc(allocator->data, nelem, n);
88 } 103 }
89 104
90 void cxFree(CxAllocator allocator, void *mem) { 105 void cxFree(
106 CxAllocator *allocator,
107 void *mem
108 ) {
91 allocator->cl->free(allocator->data, mem); 109 allocator->cl->free(allocator->data, mem);
92 } 110 }

mercurial