From ea7cd94f7aeb177618db3907a6c86b7252e018f0 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 1 Jun 2024 12:19:16 +1000 Subject: Initial commit. --- memory.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 memory.h (limited to 'memory.h') 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 -- cgit v1.2.3-54-g00ecf