From e0544300fb7da9a660a55eaf25f1996af573cd43 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 24 Feb 2019 20:01:58 +0100 Subject: Separate buffers from general allocation, but still have them in scoped allocator --- src/scoped_allocator.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/scoped_allocator.c') 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 -#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 -- cgit v1.2.3