ucx/allocator.h

changeset 173
31a8682fffb7
parent 146
aa376dba1ba8
child 174
bbfe511cfddb
equal deleted inserted replaced
172:7084e8e8433c 173:31a8682fffb7
155 * @param data argument passed to <code>free()</code> 155 * @param data argument passed to <code>free()</code>
156 */ 156 */
157 void ucx_default_free(void *ignore, void *data); 157 void ucx_default_free(void *ignore, void *data);
158 158
159 /** 159 /**
160 * Shorthand for calling an allocators malloc function.
161 * @param allocator the allocator to use
162 * @param n size of space to allocate
163 * @return a pointer to the allocated memory area
164 */
165 #define almalloc(allocator, n) ((allocator)->malloc(allocator->pool, n))
166
167 /**
168 * Shorthand for calling an allocators calloc function.
169 * @param allocator the allocator to use
170 * @param n the count of elements the space should be allocated for
171 * @param size the size of each element
172 * @return a pointer to the allocated memory area
173 */
174 #define alcalloc(allocator, n, size) \
175 ((allocator)->calloc(allocator->pool, n, size))
176
177 /**
178 * Shorthand for calling an allocators realloc function.
179 * @param allocator the allocator to use
180 * @param ptr the pointer to the memory area that shall be reallocated
181 * @param n the new size of the allocated memory area
182 * @return a pointer to the reallocated memory area
183 */
184 #define alrealloc(allocator, ptr, n) \
185 ((allocator)->realloc(allocator->pool, ptr, n))
186
187 /**
188 * Shorthand for calling an allocators free function.
189 * @param allocator the allocator to use
190 * @param ptr the pointer to the memory area that shall be freed
191 */
192 #define alfree(allocator, ptr) ((allocator)->free(allocator->pool, ptr))
193
194 /**
160 * Convenient macro for a default allocator <code>struct</code> definition. 195 * Convenient macro for a default allocator <code>struct</code> definition.
161 */ 196 */
162 #define UCX_ALLOCATOR_DEFAULT {NULL, \ 197 #define UCX_ALLOCATOR_DEFAULT {NULL, \
163 ucx_default_malloc, ucx_default_calloc, ucx_default_realloc, \ 198 ucx_default_malloc, ucx_default_calloc, ucx_default_realloc, \
164 ucx_default_free } 199 ucx_default_free }

mercurial