From 53e9e371a16ae2d167f1fc2577dff2c2426eed68 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 23 Jul 2025 15:25:22 +0200 Subject: misc(json): benchmark --- memory.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 73d6345..f60f044 100644 --- a/memory.c +++ b/memory.c @@ -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); } -- cgit v1.3