summaryrefslogtreecommitdiff
path: root/memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'memory.h')
-rw-r--r--memory.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/memory.h b/memory.h
new file mode 100644
index 0000000..7ee6f53
--- /dev/null
+++ b/memory.h
@@ -0,0 +1,43 @@
+#ifndef memory_h
+#define memory_h
+
+typedef struct {
+ char* buffer;
+ int size, blocks;
+ int usage;
+} Heap;
+
+void memory_init(void* memory);
+
+void* stack_alloc(int size);
+void* stack_alloc_aligned(int size, unsigned align);
+
+void heap_print_blocks();
+
+int get_stack_usage();
+int get_heap_usage();
+
+void init_heap(Heap* heap, char* buf, int size);
+void heap_print_blocks(const Heap* h);
+void* heap_alloc_aligned(Heap* h, int size, int align);
+void heap_free_aligned(Heap* h, void* ptr);
+void* heap_alloc(Heap* h, int size);
+void heap_free(Heap* h, void* ptr);
+
+void* galloc(int size);
+void gfree(void* ptr);
+
+typedef struct {
+ char* buffer;
+ int size, ptr;
+} Arena;
+
+void init_arena(Arena* arena, char* buffer, int size);
+void* arena_alloc(Arena* arena, int size);
+void* arena_alloc_aligned(
+ Arena* arena,
+ int size,
+ int align
+);
+
+#endif