diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-11 20:00:21 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-11 20:00:21 +0100 |
| commit | f29d35faf7cc574a1a8c109f2f609db9d3d4b5ef (patch) | |
| tree | dfd2fcbf20f3d37ffe1f19be3d0a9afb7fd24d86 /allocator.c | |
| parent | 24af775b5041cbed67dfc84f3a0d67850a4b6a1b (diff) | |
bazinga
Diffstat (limited to 'allocator.c')
| -rw-r--r-- | allocator.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/allocator.c b/allocator.c new file mode 100644 index 0000000..aaa2197 --- /dev/null +++ b/allocator.c @@ -0,0 +1,21 @@ +#include "include/allocator.h" + +allocator create_allocator(uint64_t size) { + allocator allocator; + allocator.cursor = 0; + allocator.size = size; + allocator.memory = mem_alloc(size); + return allocator; +} + +void* allocator_alloc(allocator* al, uint64_t size) { + if (al->cursor + size < al->size) { + al->cursor += size; + return al->memory + al->cursor - size; + } + log_assert(0, "Allocator out of space"); +} + +void destroy_allocator(allocator* al) { + mem_free(al->memory); +}
\ No newline at end of file |
