29 usize next_pos = current_pos + size;
32 if (next_pos > arena->
cap) {
33 ASSERT(0 &&
"Arena OOM: allocation exceeds reserved capacity");
38 if (next_pos > arena->
cmt) {
40 usize needed = next_pos - arena->
cmt;
47 ASSERT(0 &&
"Arena OOM: OS refused to commit physical RAM");
51 arena->
cmt += cmt_clamped;
54 void *result = arena->
base + current_pos;
55 arena->
pos = next_pos;
64 if (arena.
base != NULL) {
65 arena.
cap = reserve_size;
73 if (arena->
base != NULL) {
102 if (result != NULL) {
113 arena->
pos = clamped;
#define IS_POW2_OR_ZERO(x)
Checks if a given integer is a power of 2 (or zero).
#define ALIGN_UP_POW2(x, p)
Aligns a value UP to the nearest power of 2.
#define ARENA_DEFAULT_ALIGN
The default alignment for all arena_push() allocations (8 bytes).
Arena arena_create(usize reserve_size)
Creates and initializes a new arena, reserving virtual address space.
void arena_release(Arena *arena)
Releases the entire arena back to the OS, invalidating all pointers into it.
void arena_temp_end(ArenaTemp temp)
Restores the arena to the position saved in temp.
#define ARENA_COMMIT_SIZE
The granularity at which physical RAM is committed from the OS (64 KB).
void arena_clear(Arena *arena)
Resets the arena to empty by setting pos back to 0.
void * arena_push(Arena *arena, usize size)
Allocates size bytes from the arena, aligned to ARENA_DEFAULT_ALIGN.
void arena_pop_to(Arena *arena, usize pos)
Rolls the arena back to a specific byte offset.
ArenaTemp arena_temp_begin(Arena *arena)
Saves the current arena position as a rewind checkpoint.
void * arena_push_aligned(Arena *arena, usize size, usize alignment)
Allocates size bytes from the arena with an explicit power-of-2 alignment.
void * arena_push_zero(Arena *arena, usize size)
Allocates size bytes from the arena, zeroed, aligned to ARENA_DEFAULT_ALIGN.
#define ASSERT(expr)
Standard runtime assertion. Triggers a debug break on failure.
void * os_mem_reserve(usize size)
Reserves a block of virtual address space.
b32 os_mem_commit(void *ptr, usize size)
Commits physical RAM to a previously reserved address range.
void os_mem_release(void *ptr, usize size)
Releases a reserved virtual address range entirely back to the OS.
#define MEM_ZERO(ptr, size)
Wraps memset to explicitly write 0s to a block of memory.
#define MIN(a, b)
Returns the minimum of two values (Standard C fallback).
static void * arena_push_internal(Arena *arena, usize size, usize alignment)
Core allocation primitive with a caller-specified alignment.
High-performance Virtual Memory Linear (Arena) Allocator.
Operating System virtual memory wrappers.
Represents a linear memory arena backed by OS virtual memory.
A saved checkpoint into an arena, used for scoped temporary allocations.