diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2021-07-25 13:23:02 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2021-07-25 13:23:02 -0400 |
commit | 5e0e326b75402a36c4d31502b8b5a05b862ac23c (patch) | |
tree | 1b5807c1efb72dbdd9d01f329cefb41171913a64 /arm9/lib/NitroSDK/src/custom_allocator.c | |
parent | 1f9d4503c898f9138422215132b53224571a281a (diff) | |
parent | 68d7aa47cc52ef822220e0e35890863d7cad479f (diff) |
Merge remote-tracking branch 'origin/master' into pikalax_work
Diffstat (limited to 'arm9/lib/NitroSDK/src/custom_allocator.c')
-rw-r--r-- | arm9/lib/NitroSDK/src/custom_allocator.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/arm9/lib/NitroSDK/src/custom_allocator.c b/arm9/lib/NitroSDK/src/custom_allocator.c new file mode 100644 index 00000000..283c3500 --- /dev/null +++ b/arm9/lib/NitroSDK/src/custom_allocator.c @@ -0,0 +1,32 @@ +#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; +} |