aboutsummaryrefslogtreecommitdiff
path: root/src/std/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/std/buffer.c')
-rw-r--r--src/std/buffer.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c
index 5fb4b05..ddf7d39 100644
--- a/src/std/buffer.c
+++ b/src/std/buffer.c
@@ -8,9 +8,13 @@ int buffer_init(Buffer *self, struct ScopedAllocator *allocator) {
self->data = NULL;
self->size = 0;
self->capacity = 0;
- if(allocator)
- return scoped_allocator_add_buffer(allocator, self);
- return 0;
+ self->allocator = allocator;
+ if(allocator) {
+ return scoped_allocator_add_mem(allocator, &self->allocator_index);
+ } else {
+ self->allocator_index = ~0ULL;
+ return 0;
+ }
}
static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) {
@@ -36,6 +40,8 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity)
self->data = new_mem;
self->capacity = capacity;
+ if(self->allocator)
+ am_memcpy(self->allocator->mems.data + sizeof(void*) * self->allocator_index, &self->data, sizeof(void*));
return BUFFER_OK;
}