Reorganise allocators

This commit is contained in:
2024-09-07 20:27:49 +01:00
parent d30eee0cf8
commit 8468bb8e28
9 changed files with 161 additions and 96 deletions

View File

@@ -1,7 +1,10 @@
#include "mem_allocator.h"
#include <stdlib.h>
#pragma region Allocator API definitions
/******************************************************************************
**** Allocator API definitions
***************************************************************************///
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) {
if (!allocator || !(allocator->alloc)) {
return NULL;
@@ -44,4 +47,5 @@ void wapp_mem_allocator_free(const Allocator *allocator, void **ptr) {
allocator->free(ptr, allocator->obj);
}
#pragma endregion Allocator API definitions
///////////////////////////////////////////////////////////////////////////////

View File

@@ -7,16 +7,23 @@
extern "C" {
#endif // __cplusplus
#pragma region Allocator function pointer types
/******************************************************************************
**** Allocator function pointer types
***************************************************************************///
typedef void *(MemAllocFunc)(u64 size, void *alloc_obj);
typedef void *(MemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
typedef void *(MemReallocFunc)(void *ptr, u64 size, void *alloc_obj);
typedef void *(MemReallocAlignedFunc)(void *ptr, u64 size, u64 alignment,
void *alloc_obj);
typedef void(MemFreeFunc)(void **ptr, void *alloc_obj);
#pragma endregion Allocator function pointer types
#pragma region Allocator type
///////////////////////////////////////////////////////////////////////////////
/******************************************************************************
**** Allocator type
***************************************************************************///
typedef struct allocator Allocator;
struct allocator {
void *obj;
@@ -26,9 +33,13 @@ struct allocator {
MemReallocAlignedFunc *realloc_aligned;
MemFreeFunc *free;
};
#pragma endregion Allocator type
#pragma region Allocator API declarations
///////////////////////////////////////////////////////////////////////////////
/******************************************************************************
**** Allocator API declarations
***************************************************************************///
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size);
void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size,
u64 alignment);
@@ -37,7 +48,8 @@ void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr,
void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr,
u64 size, u64 alignment);
void wapp_mem_allocator_free(const Allocator *allocator, void **ptr);
#pragma endregion Allocator API declarations
///////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}