|
memory_arena
|
Scratch arena pool system for fast, reusable temporary allocations. More...
#include "arena.h"#include <pthread.h>#include <stdatomic.h>#include <stdbool.h>#include <stddef.h>
Include dependency graph for arena_scratch.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | s_scratch_arena_pool |
| Scratch arena pool structure holding multiple reusable memory arenas. More... | |
| struct | s_scratch_slot |
| Represents a single slot in the scratch arena pool. More... | |
Macros | |
| #define | SCRATCH_LOCK(pool) ((void) 0) |
Thread-safe locking macro (enabled only if ARENA_ENABLE_THREAD_SAFE is set) | |
| #define | SCRATCH_MAX_SLOTS 64 |
| Maximum number of concurrently usable scratch arenas in the pool. | |
| #define | SCRATCH_UNLOCK(pool) ((void) 0) |
Typedefs | |
| typedef struct s_scratch_arena_pool | t_scratch_arena_pool |
| Scratch arena pool structure holding multiple reusable memory arenas. | |
| typedef struct s_scratch_slot | t_scratch_slot |
| Represents a single slot in the scratch arena pool. | |
Functions | |
| t_arena * | scratch_acquire (t_scratch_arena_pool *pool) |
| Acquire a temporary scratch arena from the pool. | |
| void | scratch_pool_destroy (t_scratch_arena_pool *pool) |
| Destroy all arenas in a scratch pool and reset its metadata. | |
| bool | scratch_pool_init (t_scratch_arena_pool *pool, size_t slot_size, bool thread_safe) |
| Initialize a scratch arena pool with pre-allocated slots. | |
| void | scratch_release (t_scratch_arena_pool *pool, t_arena *arena) |
| Release a scratch arena back to the pool for reuse. | |
Scratch arena pool system for fast, reusable temporary allocations.
This module defines a pool of scratch arenas that can be acquired and released on demand. Each scratch arena is a lightweight, growable t_arena suitable for short-lived allocations in performance-critical paths such as rendering, simulation steps, or parsing tasks.
The pool supports up to SCRATCH_MAX_SLOTS concurrently usable slots. Slots are tracked using atomic flags and can be safely acquired and reused, with optional thread-safe locking.
Features:
scratch_acquire() / scratch_release()scratch_pool_destroy() before discarding a pool to release resources. Definition in file arena_scratch.h.
| #define SCRATCH_LOCK | ( | pool | ) | ((void) 0) |
Thread-safe locking macro (enabled only if ARENA_ENABLE_THREAD_SAFE is set)
Definition at line 54 of file arena_scratch.h.
| #define SCRATCH_MAX_SLOTS 64 |
Maximum number of concurrently usable scratch arenas in the pool.
Definition at line 41 of file arena_scratch.h.
| #define SCRATCH_UNLOCK | ( | pool | ) | ((void) 0) |
Definition at line 55 of file arena_scratch.h.