src/allocator.c

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

mercurial