You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
#include <stdlib.h>
|
|
|
|
#if defined(__ORBIS__) || defined(__PROSPERO__)
|
|
#define _aligned_malloc(s,a) aligned_alloc(a,s)
|
|
#define _aligned_realloc(p,s,a) reallocalign(p,s,a)
|
|
#define _aligned_free(p) free(p)
|
|
#else
|
|
#include <malloc.h>
|
|
#endif
|
|
|
|
#define DLL_EXPORT extern "C" __declspec(dllexport)
|
|
|
|
static void *AllocateMemory(size_t size, size_t alignment)
|
|
{
|
|
if (size == 0)
|
|
return nullptr;
|
|
|
|
return _aligned_malloc(size, alignment);
|
|
}
|
|
|
|
static void *ReallocateMemory(void *ptr, size_t size, size_t alignment)
|
|
{
|
|
if (size == 0)
|
|
{
|
|
free(ptr);
|
|
return nullptr;
|
|
}
|
|
|
|
// EOS will sometimes request a reallocation for a null pointer, so we need to specifically handle that
|
|
if (ptr == nullptr)
|
|
{
|
|
return _aligned_malloc(size, alignment);
|
|
}
|
|
|
|
return _aligned_realloc(ptr, size, alignment);
|
|
}
|
|
|
|
static void ReleaseMemory(void *ptr)
|
|
{
|
|
return _aligned_free(ptr);
|
|
}
|
|
|
|
typedef void* (*AllocateMemoryFunc)(size_t, size_t);
|
|
typedef void* (*ReallocateMemoryFunc)(void*, size_t, size_t);
|
|
typedef void (*ReleaseMemoryFunc)(void*);
|
|
|
|
DLL_EXPORT void EOS_GetMemoryFunctions(AllocateMemoryFunc *allocFunc, ReallocateMemoryFunc *reallocFunc, ReleaseMemoryFunc *releaseFunc)
|
|
{
|
|
*allocFunc = AllocateMemory;
|
|
*reallocFunc = ReallocateMemory;
|
|
*releaseFunc = ReleaseMemory;
|
|
}
|