1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2013 Olaf Wintermann. All rights reserved. |
4 * Copyright 2014 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
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 } |