|
cbase 1.46.11
C/C++ Static Template
|
High-performance Virtual Memory Linear (Arena) Allocator. More...


Go to the source code of this file.
Classes | |
| struct | Arena |
| Represents a linear memory arena backed by OS virtual memory. More... | |
| struct | ArenaTemp |
| A saved checkpoint into an arena, used for scoped temporary allocations. More... | |
Macros | |
| #define | ARENA_DEFAULT_ALIGN 8 |
| The default alignment for all arena_push() allocations (8 bytes). | |
| #define | ARENA_COMMIT_SIZE KB(64) |
| The granularity at which physical RAM is committed from the OS (64 KB). | |
| #define | PUSH_STRUCT(arena, type) |
| Allocates and zero-initializes a single struct on the arena. | |
| #define | PUSH_ARRAY(arena, type, count) |
| Allocates and zero-initializes an array of count elements on the arena. | |
| #define | PUSH_ARRAY_ALIGNED(arena, type, count, alignment) |
| Allocates a zero-initialized array with an explicit power-of-2 alignment. | |
Typedefs | |
| typedef struct Arena | Arena |
| Represents a linear memory arena backed by OS virtual memory. | |
| typedef struct ArenaTemp | ArenaTemp |
| A saved checkpoint into an arena, used for scoped temporary allocations. | |
Functions | |
| 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. | |
High-performance Virtual Memory Linear (Arena) Allocator.
Allocates memory by linearly advancing an offset (pos) within a large reserved virtual memory block. Physical RAM is committed from the OS automatically in 64 KB chunks as the pos grows you only pay for what you actually use.
This makes it ideal for:
Definition in file mem_arena.h.