ucx/allocator.c

changeset 888
af685cc9d623
parent 854
1c8401ece69e
equal deleted inserted replaced
877:b60487c3ec36 888:af685cc9d623
27 */ 27 */
28 28
29 #include "cx/allocator.h" 29 #include "cx/allocator.h"
30 30
31 #include <errno.h> 31 #include <errno.h>
32 #include <string.h>
32 33
33 static void *cx_malloc_stdlib( 34 static void *cx_malloc_stdlib(
34 cx_attr_unused void *d, 35 cx_attr_unused void *d,
35 size_t n 36 size_t n
36 ) { 37 ) {
58 void *mem 59 void *mem
59 ) { 60 ) {
60 free(mem); 61 free(mem);
61 } 62 }
62 63
63 static cx_allocator_class cx_default_allocator_class = { 64 static cx_allocator_class cx_stdlib_allocator_class = {
64 cx_malloc_stdlib, 65 cx_malloc_stdlib,
65 cx_realloc_stdlib, 66 cx_realloc_stdlib,
66 cx_calloc_stdlib, 67 cx_calloc_stdlib,
67 cx_free_stdlib 68 cx_free_stdlib
68 }; 69 };
69 70
70 struct cx_allocator_s cx_default_allocator = { 71 struct cx_allocator_s cx_stdlib_allocator = {
71 &cx_default_allocator_class, 72 &cx_stdlib_allocator_class,
72 NULL 73 NULL
73 }; 74 };
74 const CxAllocator * const cxDefaultAllocator = &cx_default_allocator; 75 const CxAllocator * const cxStdlibAllocator = &cx_stdlib_allocator;
76 const CxAllocator * cxDefaultAllocator = &cx_stdlib_allocator;
75 77
76 int cx_reallocate_( 78 int cx_reallocate_(
77 void **mem, 79 void **mem,
78 size_t n 80 size_t n
79 ) { 81 ) {
111 void *cxMalloc( 113 void *cxMalloc(
112 const CxAllocator *allocator, 114 const CxAllocator *allocator,
113 size_t n 115 size_t n
114 ) { 116 ) {
115 return allocator->cl->malloc(allocator->data, n); 117 return allocator->cl->malloc(allocator->data, n);
118 }
119
120 void *cxZalloc(
121 const CxAllocator *allocator,
122 size_t n
123 ) {
124 void *mem = allocator->cl->malloc(allocator->data, n);
125 if (mem != NULL) {
126 memset(mem, 0, n);
127 }
128 return mem;
116 } 129 }
117 130
118 void *cxRealloc( 131 void *cxRealloc(
119 const CxAllocator *allocator, 132 const CxAllocator *allocator,
120 void *mem, 133 void *mem,

mercurial