|
memory_arena
|
Implementation of scratch arena pool system for temporary, fast, and reusable allocations. More...
Include dependency graph for arena_scratch.c:Go to the source code of this file.
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. | |
| static bool | scratch_slot_init (t_scratch_slot *slot, size_t slot_size, int index) |
| Initialize a single scratch slot with its own arena. | |
Implementation of scratch arena pool system for temporary, fast, and reusable allocations.
This module provides a lightweight pool of scratch arenas designed for short-lived, high-performance memory allocations. A scratch arena pool contains a fixed number of slots (SCRATCH_MAX_SLOTS), each backed by its own t_arena buffer, allowing for efficient reuse without heap fragmentation or frequent allocation overhead.
Key features:
When to use:
When not to use:
API overview:
scratch_pool_init() creates a pool of pre-allocated arenas.scratch_acquire() gives out a reset arena ready for use.scratch_release() returns an arena to the pool.scratch_pool_destroy() frees all internal arenas and clears state.This implementation uses atomic_bool for per-slot locking and supports optional pthread_mutex_t if ARENA_ENABLE_THREAD_SAFE is defined.
Definition in file arena_scratch.c.