src/allocator.c

changeset 396
3539dd99ab92
parent 394
80c31ebd66c1
child 397
cfc1193b1e65
equal deleted inserted replaced
395:dc1bfe5ffd38 396:3539dd99ab92
28 28
29 #include "cx/allocator.h" 29 #include "cx/allocator.h"
30 30
31 #include <stdlib.h> 31 #include <stdlib.h>
32 32
33 cx_allocator_class cx_default_allocator_class = {
34 cx_malloc_stdlib,
35 cx_realloc_stdlib,
36 cx_calloc_stdlib,
37 cx_free_stdlib
38 };
39
33 struct cx_allocator_s cx_default_allocator = { 40 struct cx_allocator_s cx_default_allocator = {
34 { 41 &cx_default_allocator_class,
35 cx_malloc_stdlib,
36 cx_realloc_stdlib,
37 cx_calloc_stdlib,
38 cx_free_stdlib
39 },
40 NULL 42 NULL
41 }; 43 };
42 CxAllocator cxDefaultAllocator = &cx_default_allocator; 44 CxAllocator cxDefaultAllocator = &cx_default_allocator;
43 45
44 void* cx_malloc_stdlib(cx_allocator a, size_t n) { 46 void* cx_malloc_stdlib(cx_allocator a, size_t n) {
56 void cx_free_stdlib(cx_allocator a, void* mem) { 58 void cx_free_stdlib(cx_allocator a, void* mem) {
57 free(mem); 59 free(mem);
58 } 60 }
59 61
60 void* cxMalloc(CxAllocator allocator, size_t n) { 62 void* cxMalloc(CxAllocator allocator, size_t n) {
61 return allocator->allocatorClass.malloc(allocator, n); 63 return allocator->cl->malloc(allocator->data, n);
62 } 64 }
63 65
64 void* cxRealloc(CxAllocator allocator, void* mem, size_t n) { 66 void* cxRealloc(CxAllocator allocator, void* mem, size_t n) {
65 return allocator->allocatorClass.realloc(allocator, mem, n); 67 return allocator->cl->realloc(allocator->data, mem, n);
66 } 68 }
67 69
68 void* cxCalloc(CxAllocator allocator, size_t nelem, size_t n) { 70 void* cxCalloc(CxAllocator allocator, size_t nelem, size_t n) {
69 return allocator->allocatorClass.calloc(allocator, nelem, n); 71 return allocator->cl->calloc(allocator->data, nelem, n);
70 } 72 }
71 73
72 void cxFree(CxAllocator allocator, void* mem) { 74 void cxFree(CxAllocator allocator, void* mem) {
73 allocator->allocatorClass.free(allocator, mem); 75 allocator->cl->free(allocator->data, mem);
74 } 76 }

mercurial