pokeplatinum/lib/NitroSDK/include/nitro/mi/allocator.h
luckytyphlosion 320da2296d Move around library includes.
Old structure: put everything in lib/include
New structure: put library includes in their respective library folder. e.g. lib/NitroDWC/include/dwc.h
2023-01-05 18:53:16 -05:00

49 lines
1.1 KiB
C

#ifndef NITRO_MI_ALLOCATOR_H_
#define NITRO_MI_ALLOCATOR_H_
#include <nitro/misc.h>
#include <nitro/types.h>
#include <nitro/platform.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef void * (* MIAllocatorAllocFunction)(void * userdata, u32 length, u32 alignment);
typedef void (* MIAllocatorFreeFunction)(void * userdata, void * buffer);
typedef struct MIAllocator {
void * userdata;
MIAllocatorAllocFunction Alloc;
MIAllocatorFreeFunction Free;
} MIAllocator;
PLATFORM_ATTRIBUTE_INLINE
void MI_InitAllocator (MIAllocator * allocator, void * userdata,
MIAllocatorAllocFunction alloc,
MIAllocatorFreeFunction free)
{
allocator->userdata = userdata;
allocator->Alloc = alloc;
allocator->Free = free;
}
PLATFORM_ATTRIBUTE_INLINE
void * MI_CallAlloc (MIAllocator * allocator, u32 length, u32 alignment)
{
return allocator->Alloc(allocator->userdata, length, alignment);
}
PLATFORM_ATTRIBUTE_INLINE
void MI_CallFree (MIAllocator * allocator, void * buffer)
{
allocator->Free(allocator->userdata, buffer);
}
#ifdef __cplusplus
}
#endif
#endif