From efe8a104de1f2ab72b53cd1afe762f3ce13d321b Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Sun, 24 Mar 2024 21:06:41 +0000 Subject: [PATCH] Add allocator functions --- mem/src/allocator/mem_allocator.c | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 mem/src/allocator/mem_allocator.c diff --git a/mem/src/allocator/mem_allocator.c b/mem/src/allocator/mem_allocator.c new file mode 100644 index 0000000..3c9fdde --- /dev/null +++ b/mem/src/allocator/mem_allocator.c @@ -0,0 +1,45 @@ +#include "mem_allocator.h" +#include + +void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { + if (!allocator || !(allocator->alloc)) { + return NULL; + } + + return allocator->alloc(size, allocator->obj); +} + +void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, + u64 alignment) { + if (!allocator || !(allocator->alloc_aligned)) { + return NULL; + } + + return allocator->alloc_aligned(size, alignment, allocator->obj); +} + +void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, + u64 size) { + if (!allocator || !(allocator->realloc)) { + return NULL; + } + + return allocator->realloc(ptr, size, allocator->obj); +} + +void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, + u64 size, u64 alignment) { + if (!allocator || !(allocator->realloc_aligned)) { + return NULL; + } + + return allocator->realloc_aligned(ptr, size, alignment, allocator->obj); +} + +void wapp_mem_allocator_free(const Allocator *allocator, void **ptr) { + if (!allocator || !(allocator->free)) { + return; + } + + allocator->free(ptr, allocator->obj); +}