cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
mem_arena.c File Reference

Implementation of the Virtual Memory Linear (Arena) Allocator. More...

#include "memory/mem_arena.h"
#include "memory/mem_os.h"
Include dependency graph for mem_arena.c:

Go to the source code of this file.

Functions

static void * arena_push_internal (Arena *arena, usize size, usize alignment)
 Core allocation primitive with a caller-specified alignment.
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_push (Arena *arena, usize size)
 Allocates size bytes from the arena, aligned to ARENA_DEFAULT_ALIGN.
void * arena_push_zero (Arena *arena, usize size)
 Allocates size bytes from the arena, zeroed, aligned to ARENA_DEFAULT_ALIGN.
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_pop_to (Arena *arena, usize pos)
 Rolls the arena back to a specific byte offset.
void arena_clear (Arena *arena)
 Resets the arena to empty by setting pos back to 0.
ArenaTemp arena_temp_begin (Arena *arena)
 Saves the current arena position as a rewind checkpoint.
void arena_temp_end (ArenaTemp temp)
 Restores the arena to the position saved in temp.

Detailed Description

Implementation of the Virtual Memory Linear (Arena) Allocator.

Definition in file mem_arena.c.

Function Documentation

◆ arena_push_internal()

void * arena_push_internal ( Arena * arena,
usize size,
usize alignment )
static

Core allocation primitive with a caller-specified alignment.

All public push functions funnel through here so the commit logic lives in exactly one place.

Parameters
arenaThe arena to allocate from.
sizeNumber of bytes requested.
alignmentMust be a power of 2.
Returns
Aligned pointer to allocated memory, or NULL on OOM.

Definition at line 23 of file mem_arena.c.

Here is the call graph for this function:
Here is the caller graph for this function: