--- a/src/cx/allocator.h Fri May 23 14:00:24 2025 +0200 +++ b/src/cx/allocator.h Sat May 24 00:04:11 2025 +0200 @@ -228,6 +228,14 @@ cx_reallocatearray_((void**)(mem), nmemb, size) /** + * Allocates memory and sets every byte to zero. + * + * @param n (@c size_t) the number of bytes + * @return (@c void*) a pointer to the allocated memory + */ +#define cx_zalloc(n) calloc(1, n) + +/** * Free a block allocated by this allocator. * * @note Freeing a block of a different allocator is undefined. @@ -429,13 +437,33 @@ size_t size ); - +/** + * Allocate @p n bytes of memory and sets every byte to zero. + * + * @param allocator the allocator + * @param n the number of bytes + * @return a pointer to the allocated memory + */ +cx_attr_nodiscard +cx_attr_nonnull +cx_attr_malloc +cx_attr_dealloc_ucx +cx_attr_allocsize(2) +cx_attr_export +void *cxZalloc( + const CxAllocator *allocator, + size_t n +); /** * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator. */ #define cxMallocDefault(...) cxMalloc(cxDefaultAllocator, __VA_ARGS__) /** + * Convenience macro that invokes cxZalloc() with the cxDefaultAllocator. + */ +#define cxZallocDefault(...) cxZalloc(cxDefaultAllocator, __VA_ARGS__) +/** * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator. */ #define cxCallocDefault(...) cxCalloc(cxDefaultAllocator, __VA_ARGS__)