diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-23 15:25:22 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-23 15:25:22 +0200 |
| commit | 53e9e371a16ae2d167f1fc2577dff2c2426eed68 (patch) | |
| tree | e4b1d7463bc1b15eb677e263d4102892da3d58ab /memory.c | |
| parent | 2850fd0e8389a95acf12b8f66042b955cabf2d50 (diff) | |
misc(json): benchmark
Diffstat (limited to 'memory.c')
| -rw-r--r-- | memory.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -18,10 +18,13 @@ Arena Arena_new(size cap) { // alloc_align(3))) void *alloc(Arena *a, size count, size tsize, size align) { size padding = -(uptr)a->beg & (align - 1); - assert(count < (a->end - a->beg - padding) / tsize); - void *cursor = a->beg + padding; - a->beg += padding + count * tsize; - return memset(cursor, 0, count * tsize); + byte *beg = a->beg + padding; + size alloc_size = count * tsize; + assert(beg + alloc_size < a->end); + a->beg = beg + alloc_size; + return memset(beg, 0, count * tsize); } +void Arena_reset(Arena *a) { a->beg = a->end - a->cap; } + size Arena_get_used(Arena a) { return a.cap - (a.end - a.beg); } |
