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
63
64
65
66 void *(*calloc)(
67 void *data,
68 size_t nmemb,
69 size_t size
70 );
71
72
73
74
75 void (*free)(
76 void *data,
77 void *mem
78 );
79 } cx_allocator_class;
80
81
82
83
84 struct cx_allocator_s {
85
86
87
88 cx_allocator_class *cl;
89
90
91
92 void *data;
93 };
94
95
96
97
98 typedef struct cx_allocator_s CxAllocator;
99
100
101
102
103 cx_attr_export
104 extern const CxAllocator *
const cxDefaultAllocator;
105
106
107
108
109
110
111
112
113
114
115
116 typedef void (*cx_destructor_func)(
void *memory);
117
118
119
120
121
122
123
124
125
126
127
128
129 typedef void (*cx_destructor_func2)(
130 void *data,
131 void *memory
132 );
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 cx_attr_nonnull
148 cx_attr_nodiscard
149 cx_attr_export
150 int cx_reallocate_(
151 void **mem,
152 size_t n
153 );
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 cx_attr_nonnull
173 cx_attr_nodiscard
174 cx_attr_export
175 int cx_reallocatearray_(
176 void **mem,
177 size_t nmemb,
178 size_t size
179 );
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 #define cx_reallocate(mem, n) cx_reallocate_((
void**)(mem), n)
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 #define cx_reallocatearray(mem, nmemb, size) \
213 cx_reallocatearray_((
void**)(mem), nmemb, size)
214
215
216
217
218
219
220
221
222
223 cx_attr_nonnull_arg(
1)
224 cx_attr_export
225 void cxFree(
226 const CxAllocator *allocator,
227 void *mem
228 );
229
230
231
232
233
234
235
236
237 cx_attr_nodiscard
238 cx_attr_nonnull
239 cx_attr_malloc
240 cx_attr_dealloc_ucx
241 cx_attr_allocsize(
2)
242 cx_attr_export
243 void *cxMalloc(
244 const CxAllocator *allocator,
245 size_t n
246 );
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 cx_attr_nodiscard
262 cx_attr_nonnull_arg(
1)
263 cx_attr_dealloc_ucx
264 cx_attr_allocsize(
3)
265 cx_attr_export
266 void *cxRealloc(
267 const CxAllocator *allocator,
268 void *mem,
269 size_t n
270 );
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290 cx_attr_nodiscard
291 cx_attr_nonnull_arg(
1)
292 cx_attr_dealloc_ucx
293 cx_attr_allocsize(
3,
4)
294 cx_attr_export
295 void *cxReallocArray(
296 const CxAllocator *allocator,
297 void *mem,
298 size_t nmemb,
299 size_t size
300 );
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318 cx_attr_nodiscard
319 cx_attr_nonnull
320 cx_attr_export
321 int cxReallocate_(
322 const CxAllocator *allocator,
323 void **mem,
324 size_t n
325 );
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343 #define cxReallocate(allocator, mem, n) \
344 cxReallocate_(allocator, (
void**)(mem), n)
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365 cx_attr_nodiscard
366 cx_attr_nonnull
367 cx_attr_export
368 int cxReallocateArray_(
369 const CxAllocator *allocator,
370 void **mem,
371 size_t nmemb,
372 size_t size
373 );
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394 #define cxReallocateArray(allocator, mem, nmemb, size) \
395 cxReallocateArray_(allocator, (
void**) (mem), nmemb, size)
396
397
398
399
400
401
402
403
404
405 cx_attr_nonnull_arg(
1)
406 cx_attr_nodiscard
407 cx_attr_malloc
408 cx_attr_dealloc_ucx
409 cx_attr_allocsize(
2,
3)
410 cx_attr_export
411 void *cxCalloc(
412 const CxAllocator *allocator,
413 size_t nmemb,
414 size_t size
415 );
416
417 #ifdef __cplusplus
418 }
419 #endif
420
421 #endif
422