aboutsummaryrefslogtreecommitdiff
path: root/lib/alloc/arena_free.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-04-16 02:03:12 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-04-16 02:03:12 +0200
commit43b04a1bfaecfabe8b3460575db7be5d592f896b (patch)
tree86c337e90f4b4238ab73dd698f470cf3482a0de8 /lib/alloc/arena_free.c
parentbbbeab43e067a7f009b74df72ed9b083f3ecef58 (diff)
implement arena allocators
Diffstat (limited to 'lib/alloc/arena_free.c')
-rw-r--r--lib/alloc/arena_free.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/alloc/arena_free.c b/lib/alloc/arena_free.c
new file mode 100644
index 0000000..dc2b45e
--- /dev/null
+++ b/lib/alloc/arena_free.c
@@ -0,0 +1,20 @@
+#include <sys/mman.h>
+
+#include <stdlib.h>
+
+#include "alloc.h"
+#include "macros.h"
+
+void
+arena_free(arena *a)
+{
+ ASSUME(a != nullptr);
+
+ struct _region *cur, *next;
+ for (cur = a->_head; cur != nullptr; cur = next) {
+ next = cur->next;
+ munmap(cur->data, cur->cap);
+ free(cur);
+ }
+ a->_head = nullptr;
+}