memory_arena
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
arena_stack.h File Reference

Stack-based scope management for memory arenas. More...

#include "arena.h"
#include <stdbool.h>
#include <stddef.h>
+ Include dependency graph for arena_stack.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_arena_stack
 Stack structure for scoped arena memory control. More...
 
struct  s_arena_stack_frame
 Internal frame representing a single state snapshot in the stack. More...
 

Typedefs

typedef struct s_arena_stack t_arena_stack
 Stack structure for scoped arena memory control.
 
typedef struct s_arena_stack_frame t_arena_stack_frame
 Internal frame representing a single state snapshot in the stack.
 

Functions

void arena_stack_clear (t_arena_stack *stack)
 Clear all stack frames without modifying arena state.
 
void arena_stack_init (t_arena_stack *stack, t_arena *arena)
 Initialize an arena stack with a given arena.
 
void arena_stack_pop (t_arena_stack *stack)
 Pop and restore the last saved state from the stack.
 
void arena_stack_push (t_arena_stack *stack)
 Push the current arena state onto the stack.
 

Detailed Description

Stack-based scope management for memory arenas.

Author
Toonsa
Date
2025

This module defines a lightweight stack structure to manage allocation scopes within a memory arena. It enables nested usage patterns similar to function call stacks, where each push operation records a restore point, and each pop rewinds the arena back to that state using arena_pop().

Features:

Typical use case:

Note
Stack frames are themselves allocated from the arena. Be cautious when pushing deeply in arenas with tight space.

Definition in file arena_stack.h.