diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-12 09:46:01 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-12 09:46:01 +0100 |
| commit | ec3796faff12ba7bf5f775d757ac25834549903d (patch) | |
| tree | c403de62f7d53ccfebf5cb431e0d5bf25064ebee /src/allocator.c | |
| parent | 95c24b38b934f48f7f5cde37182c51857e77eac0 (diff) | |
src
Diffstat (limited to 'src/allocator.c')
| -rw-r--r-- | src/allocator.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/allocator.c b/src/allocator.c new file mode 100644 index 0000000..ffb6763 --- /dev/null +++ b/src/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 |
