Implement Allocator wrapper for memory context

This commit is contained in:
Abdelrahman Said 2024-03-24 20:30:14 +00:00
parent 03d2a59948
commit 8a58a1cc48
2 changed files with 7 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#ifndef MEM_CTX_H #ifndef MEM_CTX_H
#define MEM_CTX_H #define MEM_CTX_H
#include "mem_allocator.h"
#include "mem_arena.h" #include "mem_arena.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -14,6 +15,7 @@ typedef enum {
COUNT_CTX_DEST_BUFFER, COUNT_CTX_DEST_BUFFER,
} CTXDestBuffer; } CTXDestBuffer;
Allocator wapp_mem_ctx_allocator(CTXDestBuffer buffer);
void wapp_mem_ctx_init(u64 main_buf_capacity, u64 temp_buf_capacity); void wapp_mem_ctx_init(u64 main_buf_capacity, u64 temp_buf_capacity);
void *wapp_mem_ctx_alloc(CTXDestBuffer buffer, u64 size); void *wapp_mem_ctx_alloc(CTXDestBuffer buffer, u64 size);
void *wapp_mem_ctx_alloc_aligned(CTXDestBuffer buffer, u64 size, u64 alignment); void *wapp_mem_ctx_alloc_aligned(CTXDestBuffer buffer, u64 size, u64 alignment);

View File

@ -16,6 +16,11 @@ internal MemCTX g_context = {0};
internal Arena *get_arena(CTXDestBuffer buffer); internal Arena *get_arena(CTXDestBuffer buffer);
Allocator wapp_mem_ctx_allocator(CTXDestBuffer buffer) {
Arena *arena = get_arena(buffer);
return wapp_mem_arena_allocator(arena);
}
void wapp_mem_ctx_init(u64 main_buf_capacity, u64 temp_buf_capacity) { void wapp_mem_ctx_init(u64 main_buf_capacity, u64 temp_buf_capacity) {
g_context.main_initialised = g_context.main_initialised =
wapp_mem_arena_init(&g_context.main, main_buf_capacity); wapp_mem_arena_init(&g_context.main, main_buf_capacity);