aboutsummaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
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); }