Project
Basic C memory arena implementation
Single-header arena allocator in C99/C11 with optional aligned allocations and expansion.
Role
Systems Programming
Date
26-07-2025
Tech
C99C11MemoryAllocator
Project
Single-header arena allocator in C99/C11 with optional aligned allocations and expansion.
Systems Programming
26-07-2025
Highlights
va_c_arena is a stb-style, single-header arena allocator. Include va_arena.h, define VA_ARENA_IMPLEMENTATION once, and you get fast bump-pointer allocations with optional alignment and expansion.
arena_expand when you need more space.arena_alloc_aligned) for stricter alignment needs.arena_alloc(...); optionally use arena_alloc_aligned(...) on C11+.arena_expand(...) to grow the arena (note: existing pointers may become invalid after expansion).#include <stdio.h>
#include <stdalign.h>
#define VA_ARENA_IMPLEMENTATION
#include "va_arena.h"
typedef struct {
VA_ALIGNAS(32) int id;
VA_ALIGNAS(32) double position[3];
VA_ALIGNAS(32) char name[32];
} Entity;
int main(void) {
Arena *arena = arena_create(4096);
Entity *entities = (Entity *)arena_alloc_aligned(arena, sizeof(Entity) * 10, 32);
if (!entities) {
fprintf(stderr, "Failed to allocate aligned entities\n");
arena_destroy(&arena);
return 1;
}
// Use entities...
arena_destroy(&arena);
return 0;
}
arena_expand.