Wrap malloc
This commit is contained in:
@@ -23,6 +23,34 @@ void platform_free(void *mem)
|
|||||||
free(mem);
|
free(mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void *platform_allocator_func(Allocator *allocator, AllocOperation operation , void *memory, U32 size, U32 align)
|
||||||
|
{
|
||||||
|
switch (operation) {
|
||||||
|
case Alloc_Op_Aligned:
|
||||||
|
return aligned_alloc(size, align);
|
||||||
|
|
||||||
|
case Alloc_Op_Free: // can't free/Free_all from an marena
|
||||||
|
free(memory);
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
case Alloc_Op_Free_All:
|
||||||
|
free(memory);;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Allocator platform_allocator(void)
|
||||||
|
{
|
||||||
|
Allocator allocator = {};
|
||||||
|
allocator.op_func_ptr = platform_allocator_func;
|
||||||
|
allocator.data = NULL;
|
||||||
|
|
||||||
|
return allocator;
|
||||||
|
}
|
||||||
|
|
||||||
void *memory_allocate_and_commit(size_t size)
|
void *memory_allocate_and_commit(size_t size)
|
||||||
{
|
{
|
||||||
Assert(IsPageAligned(size));
|
Assert(IsPageAligned(size));
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "base_core.h"
|
||||||
|
|
||||||
void *platform_malloc(size_t size);
|
void *platform_malloc(size_t size);
|
||||||
|
void platform_free(void *mem);
|
||||||
|
Allocator platform_allocator(void);
|
||||||
|
|
||||||
U32 platform_page_size(void);
|
U32 platform_page_size(void);
|
||||||
|
|
||||||
// Memory functions expect mem and size to be page aligned
|
// Memory functions expect mem and size to be page aligned
|
||||||
|
|||||||
Reference in New Issue
Block a user