From e306a9fed0c6ebb7dbb616e44f8e9a9f12ef6152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sun, 24 May 2026 23:34:34 +0200 Subject: [PATCH] Add array allocations to larena --- include/larena.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/larena.h b/include/larena.h index d98f1ae..a0b1823 100644 --- a/include/larena.h +++ b/include/larena.h @@ -94,9 +94,14 @@ struct LArenaTemp { * struct foo *foo = LARENA_ALLOC_TYPE(&my_allocator, struct foo); * // Array types can be used too: * struct Foo *str = LARENA_ALLOC_TYPE(&my_allocator, struct Foo[32]); + * // For arrays with runtime determined size, use: + * LARENA_ALLOC_ARRAY(&my_allocator, struct Foo, cnt_foos); * @endcode */ #define LARENA_ALLOC_TYPE(allocator, type_) larena_alloc_aligned((allocator), sizeof(type_), _Alignof(type_)) + +#define LARENA_ALLOC_ARRAY(allocator, type_, nr_elements) larena_alloc_aligned((allocator), nr_elements * sizeof(type_), _Alignof(type_)) + // Arena size in bytes static inline size_t larena_size(const LArena *arena) {