Add allocator interface

This commit is contained in:
Nils O. Selåsdal
2026-06-21 23:41:27 +02:00
parent 1010541db7
commit e52051b859
7 changed files with 218 additions and 82 deletions
+26 -1
View File
@@ -71,7 +71,7 @@ static INLINE void *marena_push(MArena *arena, U32 size)
}
[[gnu::alloc_align(3)]]
static INLINE void *maren_push_aligned(MArena *arena, U32 size, U32 align)
static INLINE void *marena_push_aligned(MArena *arena, U32 size, U32 align)
{
Assert(IsPow2(align));
@@ -94,3 +94,28 @@ static INLINE void marena_reset(MArena *arena)
{
arena->first_free = 0;
}
static INLINE void *marena_allocator_func(Allocator *allocator, AllocOperation operation , void *memory, U32 size, U32 align)
{
switch (operation) {
case Alloc_Op_Aligned:
return marena_push_aligned(allocator->data, size, align);
case Alloc_Op_Free: // can't free/Free_all from an marena
return NULL;
case Alloc_Op_Free_All:
return NULL;
}
Assert(false);
}
static INLINE Allocator marena_allocator(MArena *arena)
{
Allocator allocator = {};
allocator.op_func_ptr = marena_allocator_func;
allocator.data = arena;
return allocator;
}