memory_arena
Loading...
Searching...
No Matches
Files | Data Structures | Typedefs | Functions
Arena State Management

Functions for inspecting and manipulating arena usage state. More...

Files

file  arena_stack.c
 Stack-based scoped memory management for arenas.
 
file  arena_stack.h
 Stack-based scope management for memory arenas.
 
file  arena_state.c
 Arena state inspection and control utilities.
 

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

Functions for inspecting and manipulating arena usage state.

These functions provide insight into memory usage (used, remaining, peak) and allow for scoped rollback (mark, pop) and reset operations.


Data Structure Documentation

◆ s_arena_stack

struct s_arena_stack

Stack structure for scoped arena memory control.

Holds a pointer to an arena and a linked list of frames representing saved arena states. Frames are allocated from the arena itself.

Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_stack.c, and arena_stack_parser.c.

Definition at line 70 of file arena_stack.h.

+ Collaboration diagram for s_arena_stack:
Data Fields
t_arena * arena Arena associated with this stack.
t_arena_stack_frame * top Top of the stack (most recent frame)

◆ s_arena_stack_frame

struct s_arena_stack_frame

Internal frame representing a single state snapshot in the stack.

Each frame holds a marker (offset) representing the arena state at the time of push, and a pointer to the previous frame for LIFO traversal.

Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_stack.c.

Definition at line 54 of file arena_stack.h.

+ Collaboration diagram for s_arena_stack_frame:
Data Fields
size_t marker Marker to rewind arena to this point.
struct s_arena_stack_frame * prev Previous frame in the stack.

Typedef Documentation

◆ t_arena_stack

typedef struct s_arena_stack t_arena_stack

#include <arena_stack.h>

Stack structure for scoped arena memory control.

Holds a pointer to an arena and a linked list of frames representing saved arena states. Frames are allocated from the arena itself.

◆ t_arena_stack_frame

#include <arena_stack.h>

Internal frame representing a single state snapshot in the stack.

Each frame holds a marker (offset) representing the arena state at the time of push, and a pointer to the previous frame for LIFO traversal.

Function Documentation

◆ arena_stack_clear()

void arena_stack_clear ( t_arena_stack *  stack)

#include <arena_stack.h>

Clear all stack frames without modifying arena state.

Clear all frames in the arena stack without altering arena memory.

Parameters
stackPointer to the arena stack to clear.
Note
This does not rewind or pop memory. It only resets the internal frame pointer.

This function discards all frames from the arena stack by resetting the top pointer to NULL. It does not modify the arena’s allocation state or release memory. It's a logical reset of the stack structure, not a memory rollback.

Use this when:

  • You want to abandon saved states without restoring them.
  • You're about to destroy the arena and want to clean up the stack pointer.
  • You're done with a scoped stack logic and want to reset for reuse.
Parameters
stackPointer to the arena stack to clear.
Returns
void
Note
This operation does not reclaim memory or modify arena contents. Use arena_stack_pop() to actually revert memory state.
Warning
Clearing the stack invalidates all saved markers in arena_stack_push(). Use with care if frames are still expected to be restored.
See also
arena_stack_init
arena_stack_push
arena_stack_pop
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_stack.c, and arena_stack_parser.c.

Definition at line 295 of file arena_stack.c.

296{
297 if (!stack)
298 return;
299 stack->top = NULL;
300}
t_arena_stack_frame * top
Top of the stack (most recent frame)
Definition arena_stack.h:73

References s_arena_stack::top.

◆ arena_stack_init()

void arena_stack_init ( t_arena_stack *  stack,
t_arena *  arena 
)

#include <arena_stack.h>

Initialize an arena stack with a given arena.

Parameters
stackPointer to the arena stack to initialize.
arenaPointer to the arena the stack will manage.
Note
Does not allocate any memory until arena_stack_push() is called.
See also
arena_stack_push
arena_stack_clear
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_stack.c, and arena_stack_parser.c.

Definition at line 144 of file arena_stack.c.

145{
146 if (!stack || !arena)
147 return;
148 stack->arena = arena;
149 stack->top = NULL;
150}
t_arena * arena
Arena associated with this stack.
Definition arena_stack.h:72

References s_arena_stack::arena, and s_arena_stack::top.

◆ arena_stack_pop()

void arena_stack_pop ( t_arena_stack *  stack)

#include <arena_stack.h>

Pop and restore the last saved state from the stack.

Restores the arena to the previous state (marker) and discards all allocations made since the last arena_stack_push() call.

Parameters
stackPointer to the arena stack to pop from.
Note
Does nothing if the stack is empty or uninitialized.
See also
arena_stack_push
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_stack.c, and arena_stack_parser.c.

Definition at line 254 of file arena_stack.c.

255{
256 if (!stack || !stack->arena || !stack->top)
257 return;
258 arena_pop(stack->arena, stack->top->marker);
259 stack->top = stack->top->prev;
260}
void arena_pop(t_arena *arena, t_arena_marker marker)
size_t marker
Marker to rewind arena to this point.
Definition arena_stack.h:56
struct s_arena_stack_frame * prev
Previous frame in the stack.
Definition arena_stack.h:57

References s_arena_stack::arena, arena_pop(), s_arena_stack_frame::marker, s_arena_stack_frame::prev, and s_arena_stack::top.

◆ arena_stack_push()

void arena_stack_push ( t_arena_stack *  stack)

#include <arena_stack.h>

Push the current arena state onto the stack.

Saves the current allocation offset into a new stack frame. All allocations made after the push can later be discarded with arena_stack_pop().

Parameters
stackPointer to the arena stack to push onto.
Note
The stack frame is allocated from the same arena being managed.
Warning
If the arena is out of memory, the push will silently fail.
See also
arena_stack_pop
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_stack.c, and arena_stack_parser.c.

Definition at line 197 of file arena_stack.c.

198{
199 if (!stack || !stack->arena)
200 return;
202 if (!frame)
203 return;
204 frame->marker = arena_mark(stack->arena);
205 frame->prev = stack->top;
206 stack->top = frame;
207}
void * arena_alloc(t_arena *arena, size_t size)
t_arena_marker arena_mark(t_arena *arena)
Internal frame representing a single state snapshot in the stack.
Definition arena_stack.h:55

References s_arena_stack::arena, arena_alloc(), arena_mark(), s_arena_stack_frame::marker, s_arena_stack_frame::prev, and s_arena_stack::top.