summaryrefslogtreecommitdiff
path: root/qstd/memory.h
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-14 23:15:34 +1100
committerquou <quou@disroot.org>2024-12-14 23:19:17 +1100
commit44e48ddc2785b037abd202a8d38b2ef2e8c36600 (patch)
treef58887ce48f7fdbf6dcca365b2a1b02a34e1b355 /qstd/memory.h
initial commit
Diffstat (limited to 'qstd/memory.h')
-rw-r--r--qstd/memory.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/qstd/memory.h b/qstd/memory.h
new file mode 100644
index 0000000..26c0382
--- /dev/null
+++ b/qstd/memory.h
@@ -0,0 +1,56 @@
+#ifndef memory_h
+#define memory_h
+
+int aligned(const void* p, int a);
+int align_size(int s, int a);
+
+typedef struct Arena {
+ char* buf;
+ int size, ptr;
+} Arena;
+
+void init_arena(
+ Arena* a,
+ void* mem,
+ int size
+);
+void clear_arena(Arena* a);
+void* arena_alloc(
+ Arena* a,
+ int size
+);
+void* arena_alloc_aligned(
+ Arena* a,
+ int size,
+ int align
+);
+
+typedef struct Heap {
+ char* buf;
+ int size, blocks;
+} Heap;
+
+void init_heap(
+ Heap* h,
+ void* mem,
+ int size
+);
+void* heap_alloc(
+ Heap* h,
+ int size
+);
+void* heap_alloc_aligned(
+ Heap* h,
+ int size,
+ int align
+);
+void heap_free_aligned(
+ Heap* h,
+ void* p
+);
+void heap_free(
+ Heap* h,
+ void* p
+);
+void heap_defrag(Heap* h);
+#endif