aboutsummaryrefslogtreecommitdiff
path: root/src/memory.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-04-08 13:14:27 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-04-08 13:15:01 +0200
commitcf534d762754860ed5b714974f99acd282d48b3b (patch)
treebf22341cedfb50ee7bcd4e15f85add2329783f31 /src/memory.c
parent630fcb1846aed16b9ab62bcf700f668883f4521f (diff)
Restructure into src/{std,json}/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/memory.c')
-rw-r--r--src/memory.c33
1 files changed, 0 insertions, 33 deletions
diff --git a/src/memory.c b/src/memory.c
deleted file mode 100644
index 7072c61..0000000
--- a/src/memory.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "../include/assert.h"
-#include "../include/memory.h"
-#include "../include/types.h"
-
-Arena Arena_new(size cap) {
- Arena a = {0};
- a.cap = cap;
- a.beg = malloc(cap);
- a.end = a.beg ? a.beg + cap : 0;
- return a;
-}
-
-// Magic to allow optimisation __attribute((malloc, alloc_size(2, 4),
-// alloc_align(3)))
-void *alloc(Arena *a, size count, size tsize, size align) {
- size padding = -(uptr)a->beg & (align - 1);
- byte *beg = a->beg + padding;
- size alloc_size = count * tsize;
- assert(beg + alloc_size < a->end, "out of memory");
- a->beg = beg + alloc_size;
- return beg;
-}
-
-void Arena_reset(Arena *a) {
- a->beg = a->end - a->cap;
- memset(a->beg, 0, a->end - a->beg);
-}
-
-size Arena_get_used(Arena a) { return a.cap - (a.end - a.beg); }