summaryrefslogtreecommitdiff
path: root/arm9/lib/src/custom_allocator.c
blob: 1b1375bc22445877c6748d589231ac22251dcd83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "global.h"
#include "custom_allocator.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;
}