cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
ArenaTemp Struct Reference

A saved checkpoint into an arena, used for scoped temporary allocations. More...

#include <mem_arena.h>

Collaboration diagram for ArenaTemp:

Public Attributes

Arenaarena
usize pos

Detailed Description

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.

Example
u8 *scratch = PUSH_ARRAY(&arena, u8, KB(4));
// ... build something temporary in scratch ...
arena_temp_end(tmp); // all temporary allocations are gone
void arena_temp_end(ArenaTemp temp)
Restores the arena to the position saved in temp.
Definition mem_arena.c:132
#define PUSH_ARRAY(arena, type, count)
Allocates and zero-initializes an array of count elements on the arena.
Definition mem_arena.h:252
ArenaTemp arena_temp_begin(Arena *arena)
Saves the current arena position as a rewind checkpoint.
Definition mem_arena.c:123
uint8_t u8
Definition base_types.h:22
#define KB(x)
Definition base_types.h:83
A saved checkpoint into an arena, used for scoped temporary allocations.
Definition mem_arena.h:105
Arena * arena
Definition mem_arena.h:106

Definition at line 105 of file mem_arena.h.

Member Data Documentation

◆ arena

Arena* ArenaTemp::arena

The arena this checkpoint belongs to.

Definition at line 106 of file mem_arena.h.

◆ pos

usize ArenaTemp::pos

The saved pos value to restore on arena_temp_end().

Definition at line 107 of file mem_arena.h.


The documentation for this struct was generated from the following file: