aboutsummaryrefslogtreecommitdiff
path: root/src/scoped_allocator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scoped_allocator.c')
-rw-r--r--src/scoped_allocator.c19
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