|
cbase 1.46.11
C/C++ Static Template
|
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. | |
| #define ARENA_COMMIT_SIZE KB(64) |
The granularity at which physical RAM is committed from the OS (64 KB).
When an allocation would exceed the currently committed range, the arena rounds the new commit size up to this boundary. Matching the Windows allocation granularity avoids wasted syscalls.
Definition at line 75 of file mem_arena.h.
| #define ARENA_DEFAULT_ALIGN 8 |
The default alignment for all arena_push() allocations (8 bytes).
Definition at line 66 of file mem_arena.h.
| #define PUSH_ARRAY | ( | arena, | |
| type, | |||
| count ) |
Allocates and zero-initializes an array of count elements on the arena.
Example:
| arena | Pointer to the Arena. |
| type | The element type (e.g., u32, struct Vertex). |
| count | Number of elements. |
Definition at line 252 of file mem_arena.h.
| #define PUSH_ARRAY_ALIGNED | ( | arena, | |
| type, | |||
| count, | |||
| alignment ) |
Allocates a zero-initialized array with an explicit power-of-2 alignment.
Example:
| arena | Pointer to the Arena. |
| type | The element type. |
| count | Number of elements. |
| alignment | Alignment in bytes (must be a power of 2). |
Definition at line 269 of file mem_arena.h.
| #define PUSH_STRUCT | ( | arena, | |
| type ) |
Allocates and zero-initializes a single struct on the arena.
Example:
| arena | Pointer to the Arena. |
| type | The struct type to allocate (e.g., MyNode). |
Definition at line 237 of file mem_arena.h.
| 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.
Call arena_temp_begin() to capture the current pos, do your allocations, then call arena_temp_end() to roll the arena back to that exact position. This is the preferred pattern for scratch/temporary work buffers.
| void arena_clear | ( | Arena * | arena | ) |
Resets the arena to empty by setting pos back to 0.
All previously returned pointers are invalidated. Physical RAM remains committed the next allocations are as fast as before. This is the idiomatic per-frame reset.
| arena | Pointer to the arena. |
Definition at line 117 of file mem_arena.c.

Creates and initializes a new arena, reserving virtual address space.
No physical RAM is consumed until the first allocation. The reserve_size may safely be set to the maximum you could ever need (e.g., GB(1)) since reservation is essentially free.
| reserve_size | Maximum capacity of the arena in bytes. |
Definition at line 60 of file mem_arena.c.

Rolls the arena back to a specific byte offset.
All memory at or above pos is considered freed. The committed physical RAM is not returned to the OS it stays mapped for future allocations.
| arena | Pointer to the arena. |
| pos | Target offset. Clamped to the current pos if larger. |
Definition at line 109 of file mem_arena.c.

Allocates size bytes from the arena, aligned to ARENA_DEFAULT_ALIGN.
Physical RAM is committed in ARENA_COMMIT_SIZE chunks as needed. In debug builds, exceeding the capacity or a commit failure triggers ASSERT. In release builds, NULL is returned on failure always check the result when size is large or dynamic.
| arena | Pointer to the arena. |
| size | Number of bytes to allocate. |
Definition at line 83 of file mem_arena.c.

Allocates size bytes from the arena with an explicit power-of-2 alignment.
Use this when allocating data that requires alignment stricter than ARENA_DEFAULT_ALIGN, such as SIMD vectors (16 or 32 bytes) or GPU-mapped buffers. The returned pointer is zeroed.
| arena | Pointer to the arena. |
| size | Number of bytes to allocate. |
| alignment | Alignment in bytes. Must be a power of 2 (e.g., 16, 32, 64). |
Definition at line 99 of file mem_arena.c.

Allocates size bytes from the arena, zeroed, aligned to ARENA_DEFAULT_ALIGN.
Equivalent to arena_push() followed by memset(result, 0, size). Prefer this over arena_push() unless you are about to overwrite the entire allocation.
| arena | Pointer to the arena. |
| size | Number of bytes to allocate and zero. |
Definition at line 89 of file mem_arena.c.

| void arena_release | ( | Arena * | arena | ) |
Releases the entire arena back to the OS, invalidating all pointers into it.
| arena | Pointer to the arena to destroy. |
Definition at line 71 of file mem_arena.c.

Saves the current arena position as a rewind checkpoint.
| arena | Pointer to the arena to checkpoint. |
Definition at line 123 of file mem_arena.c.
| void arena_temp_end | ( | ArenaTemp | temp | ) |
Restores the arena to the position saved in temp.
All allocations made after the corresponding arena_temp_begin() call are effectively freed. The physical RAM remains committed.
| temp | The checkpoint returned by arena_temp_begin(). |
Definition at line 132 of file mem_arena.c.
