166 if (!atomic_load_explicit(&arena->owns_buffer, memory_order_acquire))
170 size_t used = arena->offset;
171 const void* buf = arena->buffer;
176 FILE* f = fopen(path,
"wb");
180 bool ok = fwrite(&header,
sizeof(header), 1, f) == 1 && fwrite(buf, 1,
used, f) ==
used;
260 if (!atomic_load_explicit(&arena->owns_buffer, memory_order_acquire))
263 FILE* f = fopen(path,
"rb");
267 t_arena_snapshot_header header;
268 bool ok = fread(&header,
sizeof(header), 1, f) == 1 && strncmp(header.magic,
ARENA_SNAPSHOT_MAGIC, 9) == 0 &&
270 fread(arena->buffer, 1, header.used, f) == header.used;
273 arena->offset = header.used;
Debugging utilities and hooks for the arena memory allocator.
#define ARENA_UNLOCK(arena)
#define ARENA_LOCK(arena)
Acquire the mutex lock if thread safety is enabled.
bool arena_save_to_file(const t_arena *arena, const char *path)
Save the current contents of an arena to a file.
bool arena_load_from_file(t_arena *arena, const char *path)
Load arena contents from a snapshot file.
Arena snapshot input/output operations (save/load).
#define ARENA_SNAPSHOT_VERSION
Version number of the snapshot file format.
size_t used
Number of bytes used in the arena buffer.
#define ARENA_SNAPSHOT_MAGIC
Magic string identifying a valid arena snapshot file.
The main memory arena structure used for fast allocation.