#ifndef ARENA_H #define ARENA_H #include // size_t struct arena_ctx { void *buffer; size_t size; size_t offset; }; #define ARENA_CTX_INIT(buffer, sz) (struct arena_ctx){(buffer), (sz), 0} void *arena_allocate(struct arena_ctx *ctx, size_t sz); void arena_reset(struct arena_ctx *ctx); #ifdef ARENA_IMPLEMENTATION void *arena_allocate(struct arena_ctx *ctx, size_t sz) { if(ctx->offset + sz > ctx->size) return NULL; void *off = ctx->buffer + ctx->offset; ctx->offset += sz; return off; } void arena_reset(struct arena_ctx *ctx) { ctx->offset = 0; } #endif #endif