|
memory_arena
|
Public memory allocation functions for the arena allocator. More...
Include dependency graph for arena_alloc.c:Go to the source code of this file.
Functions | |
| void * | arena_alloc (t_arena *arena, size_t size) |
| void * | arena_alloc_aligned (t_arena *arena, size_t size, size_t alignment) |
| void * | arena_alloc_aligned_labeled (t_arena *arena, size_t size, size_t alignment, const char *label) |
| void * | arena_alloc_internal (t_arena *arena, size_t size, size_t alignment, const char *label) |
| Core internal allocator with alignment and labeling support. | |
| void * | arena_alloc_labeled (t_arena *arena, size_t size, const char *label) |
| static bool | arena_alloc_validate_input (t_arena *arena, size_t size, size_t alignment, const char *label) |
| Validate input parameters for arena allocation. | |
| static size_t | arena_calc_aligned_offset (t_arena *arena, size_t alignment) |
| Compute the next aligned offset within the arena. | |
| static bool | arena_check_overflow (t_arena *arena, size_t size, const char *label) |
| Check whether an allocation would cause a size_t overflow. | |
| static void | arena_commit_allocation (t_arena *arena, size_t size, size_t wasted, size_t aligned_offset) |
| Update offset, peak usage, and statistics. | |
| static bool | arena_ensure_capacity (t_arena *arena, size_t size, size_t alignment, const char *label, size_t *aligned_offset, size_t *wasted) |
| Ensure that the arena has enough space for a new allocation with alignment. | |
| static void | arena_invoke_allocation_hook (t_arena *arena, void *ptr, size_t size, size_t offset, size_t wasted, const char *label) |
| Invoke the user-defined allocation hook, if registered. | |
| static bool | arena_is_being_destroyed (t_arena *arena, const char *label) |
| Check whether the arena is currently being destroyed. | |
| static bool | arena_try_grow (t_arena *arena, size_t size, const char *label) |
| Attempt to grow the arena's buffer to satisfy an upcoming allocation. | |
| static void | arena_update_stats (t_arena *arena, size_t size, size_t wasted) |
| Update allocation statistics after a successful arena allocation. | |
| static void | arena_zero_if_needed (void *ptr, size_t size, const char *label) |
| Zero or poison a memory region depending on allocation label. | |
Public memory allocation functions for the arena allocator.
This file provides the main allocation interface for the arena memory system. It defines four public functions that allow clients to allocate memory from an arena with varying degrees of control over alignment and labeling:
arena_alloc(): Simple allocation with default alignment.arena_alloc_aligned(): Allocation with a custom alignment.arena_alloc_labeled(): Allocation with a debug label for tracking.arena_alloc_aligned_labeled(): Full control over alignment and labeling.Internally, all of these functions delegate to arena_alloc_internal(), which handles alignment, capacity checks, thread safety, debug labeling, and allocation hooks.
These public functions are designed to be safe, efficient, and flexible, and are the main entry points for memory allocation from a t_arena instance.
Definition in file arena_alloc.c.
| void * arena_alloc | ( | t_arena * | arena, |
| size_t | size | ||
| ) |
Definition at line 112 of file arena_alloc.c.
References arena_alloc_internal(), and ARENA_DEFAULT_ALIGNMENT.
| void * arena_alloc_aligned | ( | t_arena * | arena, |
| size_t | size, | ||
| size_t | alignment | ||
| ) |
Definition at line 167 of file arena_alloc.c.
References arena_alloc_internal().
| void * arena_alloc_aligned_labeled | ( | t_arena * | arena, |
| size_t | size, | ||
| size_t | alignment, | ||
| const char * | label | ||
| ) |
Definition at line 274 of file arena_alloc.c.
References arena_alloc_internal().
| void * arena_alloc_labeled | ( | t_arena * | arena, |
| size_t | size, | ||
| const char * | label | ||
| ) |
Definition at line 217 of file arena_alloc.c.
References arena_alloc_internal(), and ARENA_DEFAULT_ALIGNMENT.