|
memory_arena
|
Zero-initialized memory allocation functions for arenas. More...
Include dependency graph for arena_calloc.c:Go to the source code of this file.
Functions | |
| void * | arena_calloc (t_arena *arena, size_t count, size_t size) |
| void * | arena_calloc_aligned (t_arena *arena, size_t count, size_t size, size_t alignment) |
| void * | arena_calloc_aligned_labeled (t_arena *arena, size_t count, size_t size, size_t alignment, const char *label) |
| void * | arena_calloc_labeled (t_arena *arena, size_t count, size_t size, const char *label) |
| static void | arena_record_failed_alloc (t_arena *arena) |
| Increment the arena's failed allocation counter in a thread-safe manner. | |
| static bool | validate_arena_calloc_input (t_arena *arena, size_t count, size_t size) |
| Validate input parameters for a calloc-style arena allocation. | |
Zero-initialized memory allocation functions for arenas.
This file implements calloc-style memory allocation within a memory arena. It provides functions to allocate memory blocks that are automatically zero-initialized, with optional support for alignment and debug labeling.
These functions are analogous to calloc in the C standard library, but operate on arenas to enable scoped, fast allocations without direct use of the heap.
Supported use cases:
Internal helpers are used to validate parameters, detect overflows, and track failed allocation attempts in a thread-safe manner.
Definition in file arena_calloc.c.
| void * arena_calloc | ( | t_arena * | arena, |
| size_t | count, | ||
| size_t | size | ||
| ) |
Definition at line 96 of file arena_calloc.c.
References arena_calloc_labeled().
| void * arena_calloc_aligned | ( | t_arena * | arena, |
| size_t | count, | ||
| size_t | size, | ||
| size_t | alignment | ||
| ) |
Definition at line 148 of file arena_calloc.c.
References arena_calloc_aligned_labeled().
| void * arena_calloc_aligned_labeled | ( | t_arena * | arena, |
| size_t | count, | ||
| size_t | size, | ||
| size_t | alignment, | ||
| const char * | label | ||
| ) |
Definition at line 267 of file arena_calloc.c.
References arena_alloc_internal(), arena_record_failed_alloc(), arena_report_error(), validate_arena_calloc_input(), and would_overflow_mul().
| void * arena_calloc_labeled | ( | t_arena * | arena, |
| size_t | count, | ||
| size_t | size, | ||
| const char * | label | ||
| ) |
Definition at line 203 of file arena_calloc.c.
References arena_calloc_aligned_labeled(), and ARENA_DEFAULT_ALIGNMENT.
|
inlinestatic |
Increment the arena's failed allocation counter in a thread-safe manner.
This internal utility increments the failed_allocations field in the arena’s statistics structure. It is used to track the number of failed allocation attempts (due to invalid inputs, overflows, or out-of-memory conditions).
The function uses locking (via ARENA_LOCK / ARENA_UNLOCK) to ensure thread safety when statistics are modified, if thread safety is enabled.
If the arena pointer is NULL, the function exits silently.
| arena | Pointer to the t_arena whose statistics should be updated. |
Definition at line 375 of file arena_calloc.c.
References ARENA_LOCK, and ARENA_UNLOCK.
|
inlinestatic |
Validate input parameters for a calloc-style arena allocation.
This internal helper verifies that the parameters provided to arena_calloc and its variants are valid before attempting memory allocation.
Specifically, it ensures:
arena pointer is not NULL.count of elements to allocate is non-zero.size of each element is non-zero.If any condition fails, the function reports a descriptive error using arena_report_error and returns false. Otherwise, it returns true.
| arena | Pointer to the arena being used for allocation. |
| count | Number of elements to allocate. |
| size | Size (in bytes) of each element. |
true if all inputs are valid, false otherwise.Definition at line 326 of file arena_calloc.c.
References arena_report_error().