memory_arena
Loading...
Searching...
No Matches
arena_internal.h
Go to the documentation of this file.
1
19#ifndef ARENA_INTERNAL_H
20#define ARENA_INTERNAL_H
21
22#include <stdbool.h>
23#include <stddef.h>
24
25#include "arena.h"
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
32// ─────────────────────────────────────────────────────────────
33// Synchronization macros
34// ─────────────────────────────────────────────────────────────
35
41#ifdef ARENA_ENABLE_THREAD_SAFE
42#define ARENA_LOCK(arena) \
43 do \
44 { \
45 if ((arena)->use_lock) \
46 pthread_mutex_lock(&(arena)->lock); \
47 } while (0)
48
54#define ARENA_UNLOCK(arena) \
55 do \
56 { \
57 if ((arena)->use_lock) \
58 pthread_mutex_unlock(&(arena)->lock); \
59 } while (0)
60#else
61#define ARENA_LOCK(arena) ((void) 0)
62#define ARENA_UNLOCK(arena) ((void) 0)
63#endif
64
65 // ─────────────────────────────────────────────────────────────
66 // Internal helper functions
67 // ─────────────────────────────────────────────────────────────
68
78 bool arena_is_valid(const t_arena* arena);
79
95 size_t default_grow_cb(size_t current_size, size_t requested_size);
96
106 void arena_update_peak(t_arena* arena);
107
117 void arena_zero_metadata(t_arena* arena);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif // ARENA_INTERNAL_H
Core public API for the Arena memory allocator.
void arena_zero_metadata(t_arena *arena)
Zero out and reset all debug/stats metadata associated with the arena.
bool arena_is_valid(const t_arena *arena)
Check whether the given arena is in a valid, initialized state.
size_t default_grow_cb(size_t current_size, size_t requested_size)
Default growth policy callback for arena resizing.
void arena_update_peak(t_arena *arena)
Update the arena’s peak memory usage if the current usage exceeds it.
The main memory arena structure used for fast allocation.