diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-21 14:22:44 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-21 14:22:44 -0400 |
commit | 716572be08ec797a4d23d6c3b86f41ba66678651 (patch) | |
tree | c6a5da789c8f4a9fbc8cb10bd9172e4ed330abb1 /arm9/lib/src/custom_allocator.c | |
parent | 2c85377e09f9ec0ab5821e221c42dc775e6db1f1 (diff) |
Some cleanup
Diffstat (limited to 'arm9/lib/src/custom_allocator.c')
-rw-r--r-- | arm9/lib/src/custom_allocator.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/arm9/lib/src/custom_allocator.c b/arm9/lib/src/custom_allocator.c new file mode 100644 index 00000000..869901ce --- /dev/null +++ b/arm9/lib/src/custom_allocator.c @@ -0,0 +1,32 @@ +#include "global.h" + +typedef void * (* AllocFunc)(u32 size); +typedef void (* FreeFunc)(void * ptr); + +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; +} |