Support > 4GB of chained arenas

This commit is contained in:
Nils O. Selåsdal
2026-06-09 15:33:08 +02:00
parent 41530a2a53
commit f4cf833339
2 changed files with 19 additions and 17 deletions
+5 -4
View File
@@ -17,7 +17,7 @@ struct MemoryBlock {
U32 size; // Block size, page aligned
U32 pos; // start of next allocation
U64 base_pos; // absolute position of base relative to the first linked arena
U32 committed_pos; // end of committed region. Will be page aligned
U32 committed_end; // end of committed region. Will be page aligned
MemoryBlock *prev;
};
@@ -34,7 +34,7 @@ struct Arena {
typedef struct ArenaCheckpoint ArenaCheckpoint;
struct ArenaCheckpoint {
Arena *arena;
U32 absolute_pos;
U64 absolute_pos;
};
#ifndef ArenaParams_Default
#define ArenaParams_Default { .size = MB(32), .commit_size = KB(64) }
@@ -49,11 +49,12 @@ void arena_free(Arena *arena);
void *arena_push(Arena *arena, U32 size, U32 align);
#define arena_push_type(arena, type) arena_push(arena, (U32)sizeof(type), alignof(type))
// Invalid for arrays > U32
#define arena_push_array_of(arena, type, len) arena_push(arena, (U32) (sizeof(type) * (len)), alignof(type))
ArenaCheckpoint arena_temp_begin(Arena *arena);
void arena_temp_end(ArenaCheckpoint *checkpoint);
void arena_pop_to(Arena *arena, U32 abs_pos);
void arena_pop_to(Arena *arena, U64 abs_pos);
void arena_reset(Arena *arena);
static INLINE U32 memoryblock_available(const MemoryBlock *block)
@@ -61,7 +62,7 @@ static INLINE U32 memoryblock_available(const MemoryBlock *block)
return block->size - block->pos;
}
static INLINE U32 arena_used(const Arena *arena)
static INLINE U64 arena_used(const Arena *arena)
{
const MemoryBlock *block = arena->current;
return block->base_pos + block->pos;