aboutsummaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-23 15:25:22 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-23 15:25:22 +0200
commit53e9e371a16ae2d167f1fc2577dff2c2426eed68 (patch)
treee4b1d7463bc1b15eb677e263d4102892da3d58ab /memory.c
parent2850fd0e8389a95acf12b8f66042b955cabf2d50 (diff)
misc(json): benchmark
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c11
1 files changed, 7 insertions, 4 deletions
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); }