diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-24 20:01:58 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | e0544300fb7da9a660a55eaf25f1996af573cd43 (patch) | |
tree | d6e375f78f10a0c9ad16d984aa218234a5d078e1 /src/scoped_allocator.c | |
parent | 204a1cc2b01ed3f18cb3e33bd6aa756d1f99dda8 (diff) |
Separate buffers from general allocation, but still have them in scoped allocator
Diffstat (limited to 'src/scoped_allocator.c')
-rw-r--r-- | src/scoped_allocator.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/scoped_allocator.c b/src/scoped_allocator.c index cbf1aad..7e2cb0d 100644 --- a/src/scoped_allocator.c +++ b/src/scoped_allocator.c @@ -2,7 +2,7 @@ #include "../include/alloc.h" #include <assert.h> -#define ALLOC_NODE_SIZE 65536 +#define ALLOC_NODE_SIZE 4096 int scoped_allocator_node_init(ScopedAllocatorNode *self) { self->data = NULL; @@ -25,11 +25,22 @@ void scoped_allocator_node_deinit(ScopedAllocatorNode *self) { int scoped_allocator_init(ScopedAllocator *self) { return_if_error(scoped_allocator_node_init(&self->head)); self->current = &self->head; - return 0; + return buffer_init(&self->buffers, NULL); } + void scoped_allocator_deinit(ScopedAllocator *self) { + Buffer *buffer; + Buffer *buffer_end; + scoped_allocator_node_deinit(&self->head); self->current = NULL; + buffer = (Buffer*)&self->buffers.data[0]; + buffer_end = buffer + self->buffers.size / sizeof(Buffer); + while(buffer != buffer_end) { + buffer_deinit(buffer); + ++buffer; + } + buffer_deinit(&self->buffers); } static CHECK_RESULT int scoped_allocator_ensure_capacity_for(ScopedAllocator *self, usize size) { @@ -57,4 +68,8 @@ int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem) { *mem = &self->current->data[self->current->size]; self->current->size += size; return 0; +} + +int scoped_allocator_add_buffer(ScopedAllocator *self, Buffer *buffer) { + return buffer_append(&self->buffers, buffer, sizeof(buffer)); }
\ No newline at end of file |