diff options
author | quou <quou@disroot.org> | 2024-06-01 12:19:16 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-06-01 12:20:17 +1000 |
commit | ea7cd94f7aeb177618db3907a6c86b7252e018f0 (patch) | |
tree | e972f9cf590ef756c2e41f3eac5b03e16db08300 /memory.h |
Initial commit.
Diffstat (limited to 'memory.h')
-rw-r--r-- | memory.h | 43 |
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 |