wrote with_arena macro

This commit is contained in:
2025-11-25 22:18:54 +01:00
parent df496f73ef
commit 6dc0caceeb
3 changed files with 34 additions and 3 deletions
+21
View File
@@ -0,0 +1,21 @@
#include <criterion/criterion.h>
#include "cig.h"
Test(arena_allocator, repeated_allocations) {
arena_allocator_t aalloc = arena_allocator_create();
for ( int i = 0; i < 10; i++ ) {
with_arena(&aalloc, allocator) {
allocator_alloc(allocator, 10);
}
}
cr_assert_eq(aalloc.total_allocated, 10);
cr_assert_eq(borrow_allocator_count_allocations(&aalloc.borrow_allocator), 0);
cr_assert_eq(dyn_array_capacity(aalloc.bytes), 10);
arena_allocator_destroy(&aalloc);
cr_assert_eq(aalloc.total_allocated, 0);
}
// TODO somehow test reallocations