memory_arena
Loading...
Searching...
No Matches
Files | Functions
Thread-Local Scratch Arena

Lightweight, thread-local memory arenas for fast temporary allocations. More...

Files

file  arena_tlscratch.h
 Thread-local scratch arena interface for fast temporary allocations.
 

Functions

void destroy_thread_scratch_arena (void)
 Destroy the thread-local scratch arena for the calling thread.
 
t_arena * get_thread_scratch_arena (void)
 Get the thread-local scratch arena, resetting it before use.
 
t_arena * get_thread_scratch_arena_ref (void)
 Access the raw thread-local arena pointer without initialization.
 
void set_thread_scratch_arena_size (size_t size)
 Configure the initial size for the thread-local scratch arena.
 

Detailed Description

Lightweight, thread-local memory arenas for fast temporary allocations.

This group provides functions for accessing a private scratch arena that is unique per thread. These arenas are lazily initialized and automatically reset on each access to ensure clean, reusable memory without synchronization.

Use cases include:

The thread-local scratch arena system is enabled via the ARENA_ENABLE_THREAD_LOCAL_SCRATCH macro.

Note
This system is independent of the global scratch_arena_pool. It is not safe to share the returned arena between threads.

Function Documentation

◆ destroy_thread_scratch_arena()

void destroy_thread_scratch_arena ( void  )

#include <arena_tlscratch.h>

Destroy the thread-local scratch arena for the calling thread.

Note
This resets internal state and frees any allocated buffer.
See also
get_thread_scratch_arena
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_tlscratch.c.

Definition at line 295 of file arena_tlscratch.c.

296{
297 arena_report_error(NULL, "destroy_thread_scratch_arena() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is disabled");
298}
void arena_report_error(t_arena *arena, const char *fmt,...)
Report an error from an arena using its configured error callback.

References arena_report_error().

◆ get_thread_scratch_arena()

t_arena * get_thread_scratch_arena ( void  )

#include <arena_tlscratch.h>

Get the thread-local scratch arena, resetting it before use.

Returns
Pointer to the thread-local t_arena, or NULL if disabled or failed.
See also
destroy_thread_scratch_arena
set_thread_scratch_arena_size
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_tlscratch.c.

Definition at line 289 of file arena_tlscratch.c.

290{
291 arena_report_error(NULL, "get_thread_scratch_arena() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is disabled");
292 return NULL;
293}

References arena_report_error().

◆ get_thread_scratch_arena_ref()

t_arena * get_thread_scratch_arena_ref ( void  )

#include <arena_tlscratch.h>

Access the raw thread-local arena pointer without initialization.

Returns
Raw pointer to the current thread's t_arena.
Warning
May return an uninitialized arena if accessed before get_thread_scratch_arena().
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_tlscratch.c.

Definition at line 307 of file arena_tlscratch.c.

308{
309 arena_report_error(NULL, "get_thread_scratch_arena_ref() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is disabled");
310 return NULL;
311}

References arena_report_error().

◆ set_thread_scratch_arena_size()

void set_thread_scratch_arena_size ( size_t  size)

#include <arena_tlscratch.h>

Configure the initial size for the thread-local scratch arena.

Parameters
sizeDesired size in bytes.
Note
Must be called before get_thread_scratch_arena() is used in the same thread.
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/arena_tlscratch.c.

Definition at line 300 of file arena_tlscratch.c.

301{
302 (void)size;
303 arena_report_error(NULL, "set_thread_scratch_arena_size() called but ARENA_ENABLE_THREAD_LOCAL_SCRATCH is "
304 "disabled");
305}

References arena_report_error().