mirror of
https://github.com/pret/pokediamond.git
synced 2026-09-30 15:26:57 -04:00
9ff579dac8
Not complete, but a good start.
33 lines
693 B
C
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;
|
|
}
|