diff options
Diffstat (limited to 'util/arena.h')
| -rw-r--r-- | util/arena.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/util/arena.h b/util/arena.h index 3d82b95..1142321 100644 --- a/util/arena.h +++ b/util/arena.h @@ -9,18 +9,26 @@ struct arena_ctx { 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 +#define ARENA_ALLIGNMENT 2 +// #include <assert.h> void *arena_allocate(struct arena_ctx *ctx, size_t sz) { + if(sz % ARENA_ALLIGNMENT != 0) + sz += ARENA_ALLIGNMENT - (sz % ARENA_ALLIGNMENT); + if(ctx->offset + sz > ctx->size) return NULL; - void *off = ctx->buffer + ctx->offset; + void *off = (void *)((intptr_t)ctx->buffer + ctx->offset); ctx->offset += sz; + + // assert(((intptr_t)off & 0x1) == 0); return off; } |
