some buffer allocator progress

This commit is contained in:
2025-10-05 20:14:47 +02:00
parent ddf9bea20b
commit 6374c47a62
2 changed files with 40 additions and 14 deletions
+31 -7
View File
@@ -1,22 +1,43 @@
#include "allocator.h"
// TODO
void *buffer_allocator_alloc(buffer_allocator_t *this, size_t bytes) {
size_t new_size = this->size + bytes;
if (new_size > this->capacity) {
return NULL;
}
void *ptr = &this->data[this->size]
this->size = new_size;
return ptr;
}
void *buffer_allocator_resize(buffer_allocator_t *this, void *old_ptr, size_t bytes) {
// TODO: check if the pointer is even in the buffer?
void *new_ptr = buffer_allocator_alloc(this, bytes);
if (new_ptr == NULL) {
return NULL;
}
// TODO: copy over data
}
void buffer_allocator_reset(buffer_allocator_t *this) {
this->size = 0;
}
static void *buffer_alloc(void *this, size_t bytes, const char *file, int line) {
(void)this;
(void)bytes;
(void)file;
(void)line;
return 0;
return buffer_allocator_alloc((buffer_allocator_t *)this, bytes);
}
static void *buffer_resize(void *this, void *old_ptr, size_t bytes, const char *file, int line) {
(void)this;
(void)old_ptr;
(void)bytes;
(void)file;
(void)line;
return 0;
// TODO: do the concrete implementation first!
void *new_ptr = buffer_allocator_alloc((buffer_allocator_t *)this, bytes);
}
static void buffer_free(void *this, void *ptr, const char *file, int line) {
(void)this;
(void)ptr;
@@ -29,3 +50,6 @@ static const allocator_vtbl_t buffer_vtbl = {
.resize = buffer_resize,
.free = buffer_free,
};
allocator_t buffer_allocator_interface(buffer_allocator_t *this) {
}