1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #ifndef UCX_ALLOCATOR_H
34 #define UCX_ALLOCATOR_H
35
36 #include "common.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42
43
44
45 typedef struct {
46
47
48
49 void *(*malloc)(
50 void *data,
51 size_t n
52 );
53
54
55
56
57 void *(*realloc)(
58 void *data,
59 void *mem,
60 size_t n
61 )
62 __attribute__((__warn_unused_result__));
63
64
65
66
67 void *(*calloc)(
68 void *data,
69 size_t nelem,
70 size_t n
71 );
72
73
74
75
76 void (*free)(
77 void *data,
78 void *mem
79 )
80 __attribute__((__nonnull__));
81 } cx_allocator_class;
82
83
84
85
86 struct cx_allocator_s {
87
88
89
90 cx_allocator_class *cl;
91
92
93
94 void *data;
95 };
96
97
98
99
100 typedef struct cx_allocator_s CxAllocator;
101
102
103
104
105 extern CxAllocator *cxDefaultAllocator;
106
107
108
109
110
111
112
113
114
115
116
117 typedef void (*cx_destructor_func)(
void *memory) __attribute__((__nonnull__));
118
119
120
121
122
123
124
125
126
127
128
129
130 typedef void (*cx_destructor_func2)(
131 void *data,
132 void *memory
133 ) __attribute__((__nonnull__(
2)));
134
135
136
137
138
139
140
141
142 void *cxMalloc(
143 CxAllocator
const *allocator,
144 size_t n
145 )
146 __attribute__((__malloc__))
147 __attribute__((__alloc_size__(
2)));
148
149
150
151
152
153
154
155
156
157
158
159
160
161 void *cxRealloc(
162 CxAllocator
const *allocator,
163 void *mem,
164 size_t n
165 )
166 __attribute__((__warn_unused_result__))
167 __attribute__((__alloc_size__(
3)));
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 int cxReallocate(
185 CxAllocator
const *allocator,
186 void **mem,
187 size_t n
188 )
189 __attribute__((__nonnull__));
190
191
192
193
194
195
196
197
198
199 void *cxCalloc(
200 CxAllocator
const *allocator,
201 size_t nelem,
202 size_t n
203 )
204 __attribute__((__malloc__))
205 __attribute__((__alloc_size__(
2,
3)));
206
207
208
209
210
211
212
213
214
215 void cxFree(
216 CxAllocator
const *allocator,
217 void *mem
218 )
219 __attribute__((__nonnull__));
220
221 #ifdef __cplusplus
222 }
223 #endif
224
225 #endif
226