diff options
author | quou <quou@disroot.org> | 2024-06-30 18:24:01 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-06-30 18:27:11 +1000 |
commit | 39100e7292d3ee12d387fddfa0f0d7b712e31e1c (patch) | |
tree | 28f26b19de857868aeb9ecf23a7fecfc170addf9 /memory.h |
initial commit.
Diffstat (limited to 'memory.h')
-rw-r--r-- | memory.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/memory.h b/memory.h new file mode 100644 index 0000000..1dc5021 --- /dev/null +++ b/memory.h @@ -0,0 +1,56 @@ +#ifndef memory_h +#define memory_h + +int aligned(void* p, int a); +int align_size(int s, int a); + +typedef struct { + 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 { + 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 |