Files
pokediamond/arm9/lib/src/custom_allocator.c
T
Michael Panzlaff 9ff579dac8 cleanup header includes and orders
Not complete, but a good start.
2021-06-24 15:57:31 +02:00

33 lines
693 B
C

#include "custom_allocator.h"
#include "global.h"
#include "OS_alloc.h"
static FreeFunc sDestructor;
static AllocFunc sAllocator;
// Custom allocator
ARM_FUNC void* CallCustomAllocator(u32 size)
{
if (sAllocator != NULL)
return sAllocator(size);
else
return OS_AllocFromHeap(OS_ARENA_MAIN, -1, size);
}
// Custom destructor
ARM_FUNC void CallCustomDestructor(void * ptr)
{
if (sDestructor != NULL)
sDestructor(ptr);
else
OS_FreeToHeap(OS_ARENA_MAIN, -1, ptr);
}
// Custom alloc/free setter
ARM_FUNC void SetCustomAllocatorAndDestructor(AllocFunc allocator, FreeFunc destructor)
{
sAllocator = allocator;
sDestructor = destructor;
}