226 */ |
226 */ |
227 #define cx_reallocatearray(mem, nmemb, size) \ |
227 #define cx_reallocatearray(mem, nmemb, size) \ |
228 cx_reallocatearray_((void**)(mem), nmemb, size) |
228 cx_reallocatearray_((void**)(mem), nmemb, size) |
229 |
229 |
230 /** |
230 /** |
|
231 * Allocates memory and sets every byte to zero. |
|
232 * |
|
233 * @param n (@c size_t) the number of bytes |
|
234 * @return (@c void*) a pointer to the allocated memory |
|
235 */ |
|
236 #define cx_zalloc(n) calloc(1, n) |
|
237 |
|
238 /** |
231 * Free a block allocated by this allocator. |
239 * Free a block allocated by this allocator. |
232 * |
240 * |
233 * @note Freeing a block of a different allocator is undefined. |
241 * @note Freeing a block of a different allocator is undefined. |
234 * |
242 * |
235 * @param allocator the allocator |
243 * @param allocator the allocator |
427 const CxAllocator *allocator, |
435 const CxAllocator *allocator, |
428 size_t nmemb, |
436 size_t nmemb, |
429 size_t size |
437 size_t size |
430 ); |
438 ); |
431 |
439 |
432 |
440 /** |
|
441 * Allocate @p n bytes of memory and sets every byte to zero. |
|
442 * |
|
443 * @param allocator the allocator |
|
444 * @param n the number of bytes |
|
445 * @return a pointer to the allocated memory |
|
446 */ |
|
447 cx_attr_nodiscard |
|
448 cx_attr_nonnull |
|
449 cx_attr_malloc |
|
450 cx_attr_dealloc_ucx |
|
451 cx_attr_allocsize(2) |
|
452 cx_attr_export |
|
453 void *cxZalloc( |
|
454 const CxAllocator *allocator, |
|
455 size_t n |
|
456 ); |
433 |
457 |
434 /** |
458 /** |
435 * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator. |
459 * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator. |
436 */ |
460 */ |
437 #define cxMallocDefault(...) cxMalloc(cxDefaultAllocator, __VA_ARGS__) |
461 #define cxMallocDefault(...) cxMalloc(cxDefaultAllocator, __VA_ARGS__) |
|
462 /** |
|
463 * Convenience macro that invokes cxZalloc() with the cxDefaultAllocator. |
|
464 */ |
|
465 #define cxZallocDefault(...) cxZalloc(cxDefaultAllocator, __VA_ARGS__) |
438 /** |
466 /** |
439 * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator. |
467 * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator. |
440 */ |
468 */ |
441 #define cxCallocDefault(...) cxCalloc(cxDefaultAllocator, __VA_ARGS__) |
469 #define cxCallocDefault(...) cxCalloc(cxDefaultAllocator, __VA_ARGS__) |
442 /** |
470 /** |