|
memory_arena
|
Arena memory resizing logic — dynamic growth and shrinking. More...
Include dependency graph for arena_resize.c:Go to the source code of this file.
Functions | |
| static bool | arena_can_shrink (t_arena *arena, size_t new_size) |
| Determine whether the arena is eligible for shrinking to a smaller size. | |
| bool | arena_grow (t_arena *arena, size_t required_size) |
| static size_t | arena_grow_compute_new_size (t_arena *arena, size_t required_size) |
| Compute the new size for the arena based on the growth policy. | |
| static bool | arena_grow_realloc_buffer (t_arena *arena, size_t new_size, size_t old_size) |
| Reallocate the arena's buffer to a new size. | |
| static bool | arena_grow_validate (t_arena *arena, size_t required_size) |
| Validate whether the arena is allowed to grow for a given request. | |
| bool | arena_might_shrink (t_arena *arena) |
| static void | arena_record_growth (t_arena *arena, size_t old_size) |
| Record the previous size of the arena in the growth history. | |
| static bool | arena_should_grow (const t_arena *arena) |
| Check whether the arena is allowed to grow. | |
| static bool | arena_should_maybe_shrink (size_t used, size_t size) |
| Decide whether the arena buffer should be shrunk based on usage ratio. | |
| void | arena_shrink (t_arena *arena, size_t new_size) |
| static bool | arena_shrink_apply (t_arena *arena, size_t new_size) |
| Apply the memory shrink operation to an arena's buffer. | |
| static size_t | arena_shrink_target (size_t used) |
| Compute the target buffer size for a shrink operation. | |
| static bool | arena_shrink_validate (t_arena *arena, size_t new_size) |
| Validate whether an arena can be safely shrunk to a new size. | |
| static bool | should_attempt_shrink (t_arena *arena) |
| Determine whether the arena is eligible for dynamic shrinking. | |
Arena memory resizing logic — dynamic growth and shrinking.
This file implements the dynamic memory resizing features of the arena allocator, allowing it to grow when allocations exceed current capacity, and shrink when memory usage drops significantly.
Features covered in this file:
arena_grow) based on requested size.arena_shrink) of underused memory regions.arena_might_shrink) with safe thresholds.All operations are thread-safe and acquire internal locks on the arena during mutation of memory size or related metadata.
This module is especially useful for long-lived arenas in high-uptime applications, where memory usage patterns may fluctuate and reclaiming unused memory is desirable.
Definition in file arena_resize.c.
| bool arena_grow | ( | t_arena * | arena, |
| size_t | required_size | ||
| ) |
Definition at line 142 of file arena_resize.c.
References arena_grow_compute_new_size(), arena_grow_realloc_buffer(), arena_grow_validate(), ARENA_LOCK, arena_report_error(), and ARENA_UNLOCK.
| bool arena_might_shrink | ( | t_arena * | arena | ) |
Definition at line 385 of file arena_resize.c.
References ARENA_CHECK, ARENA_LOCK, arena_should_maybe_shrink(), arena_shrink(), arena_shrink_target(), ARENA_UNLOCK, should_attempt_shrink(), and used.
| void arena_shrink | ( | t_arena * | arena, |
| size_t | new_size | ||
| ) |
Definition at line 267 of file arena_resize.c.
References ARENA_CHECK, ARENA_LOCK, arena_shrink_apply(), arena_shrink_validate(), and ARENA_UNLOCK.