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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #ifndef UCX_ALLOCATOR_H
53 #define UCX_ALLOCATOR_H
54
55 #include "ucx.h"
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62
63
64
65 typedef void*(*ucx_allocator_malloc)(
void *pool,
size_t n);
66
67
68
69
70
71 typedef void*(*ucx_allocator_calloc)(
void *pool,
size_t n,
size_t size);
72
73
74
75
76
77 typedef void*(*ucx_allocator_realloc)(
void *pool,
void *data,
size_t n);
78
79
80
81
82
83 typedef void(*ucx_allocator_free)(
void *pool,
void *data);
84
85
86
87
88 typedef struct {
89
90
91
92
93 void *pool;
94
95
96
97 ucx_allocator_malloc malloc;
98
99
100
101 ucx_allocator_calloc calloc;
102
103
104
105 ucx_allocator_realloc realloc;
106
107
108
109 ucx_allocator_free free;
110 } UcxAllocator;
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 UcxAllocator *ucx_default_allocator();
128
129
130
131
132
133
134
135 void *ucx_default_malloc(
void *ignore,
size_t n);
136
137
138
139
140
141
142
143 void *ucx_default_calloc(
void *ignore,
size_t n,
size_t size);
144
145
146
147
148
149
150
151 void *ucx_default_realloc(
void *ignore,
void *data,
size_t n);
152
153
154
155
156
157 void ucx_default_free(
void *ignore,
void *data);
158
159
160
161
162
163
164
165 #define almalloc(allocator, n) ((allocator)->malloc((allocator)->pool, n))
166
167
168
169
170
171
172
173
174 #define alcalloc(allocator, n, size) \
175 ((allocator)->calloc((allocator)->pool, n, size))
176
177
178
179
180
181
182
183
184 #define alrealloc(allocator, ptr, n) \
185 ((allocator)->realloc((allocator)->pool, ptr, n))
186
187
188
189
190
191
192 #define alfree(allocator, ptr) ((allocator)->free((allocator)->pool, ptr))
193
194
195
196
197 #define UCX_ALLOCATOR_DEFAULT {
NULL, \
198 ucx_default_malloc, ucx_default_calloc, ucx_default_realloc, \
199 ucx_default_free }
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif
206
207