From 7b6af7028f3c12ec670a496adf58fee312215529 Mon Sep 17 00:00:00 2001 From: Cristian Gora Date: Tue, 7 Jul 2026 06:48:32 +0200 Subject: [PATCH] v1.2.3 --- arena.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arena.h b/arena.h index 144811f..0c9b172 100644 --- a/arena.h +++ b/arena.h @@ -1,4 +1,4 @@ -// arena.h - v1.2.2 - MIT License +// arena.h - v1.2.3 - MIT License // single header library for region-based memory management. // // [License and changelog] @@ -96,6 +96,12 @@ // This function allocates a buffer of bytes into the specified arena // and returns it's pointer. // +// void *arena_calloc(Arena *a, size_t count, size_t size) +// +// This function allocates a buffer of * bytes into the +// specified arena and returns it's pointer. The resulting buffer will be +// zero-initialized just like the standard calloc() function. +// // void *arena_copy(Arena *a, const void *src, size_t size); // // This function allocates a buffer of bytes into the arena and copies @@ -218,6 +224,7 @@ void arena_trim(Arena *a); // Allocation and other utilities void *arena_alloc(Arena *a, size_t size); +void *arena_calloc(Arena *a, size_t count, size_t size); void *arena_copy(Arena *a, const void *src, size_t size); char *arena_strdup(Arena *a, const char *s); char *arena_sprintf(Arena *a, const char *fmt, ...); @@ -382,6 +389,22 @@ void *arena_alloc(Arena *a, size_t size) return a->tail->data; } +void *arena_calloc(Arena *a, size_t count, size_t size) +{ + if (a == NULL) { + ARENA_ASSERT(false && "Invalid parameters"); + return NULL; + } + + void *result = arena_alloc(a, count * size); + + if (result != NULL) { + memset(result, 0, count * size); + } + + return result; +} + void *arena_copy(Arena *a, const void *src, size_t size) { if (a == NULL || src == NULL) { @@ -518,6 +541,7 @@ size_t arena__align(size_t n) /* * Revision history: * + * 1.2.3 (2026-07-07) New function: arena_calloc() * 1.2.2 (2026-07-07) Fix various memory problems; * make ARENA_REGION_GROWTH_FACTOR an integer * 1.2.1 (2026-04-08) Region growth factor handling with new