#include "arena.h" #include "../aliases.h" #include #include bool arena_init(arena_t *arena, u64 capacity) { arena->buf = (u8 *)malloc(capacity); if (!(arena->buf)) { return false; } arena->capacity = capacity; arena->offset = arena->buf; return true; } u8 *arena_alloc(arena_t *arena, u64 size) { if (arena->offset + size >= arena->buf + arena->capacity) { return NULL; } u8 *output = arena->offset; arena->offset += size; return output; } void arena_clear(arena_t *arena) { memset(arena->buf, 0, arena->offset - arena->buf); arena->offset = arena->buf; } void arena_free(arena_t *arena) { arena->capacity = 0; arena->offset = NULL; if (arena->buf) { free(arena->buf); } arena->buf = NULL; }