2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 13:44:56 +00:00

CMemory falls back to malloc if uninitialized

This commit is contained in:
Jack Andersen
2015-12-02 12:05:44 -10:00
parent 04fa61e0c2
commit 3fbbff133c
2 changed files with 19 additions and 1 deletions

View File

@@ -73,6 +73,8 @@ IAllocator& CMemorySys::GetGameAllocator() {return g_gameAllocator;}
void* operator new(std::size_t sz)
{
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs("?\?(?\?)", "UnknownType");
return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None,
@@ -84,6 +86,8 @@ void* operator new(std::size_t sz)
void* operator new(std::size_t sz,
const char* funcName, const char* typeName)
{
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs(funcName, typeName);
return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None,
@@ -94,11 +98,18 @@ void* operator new(std::size_t sz,
void operator delete(void* ptr) noexcept
{
if (!Retro::g_memoryAllocatorReady)
{
free(ptr);
return;
}
Retro::CMemory::Free(ptr);
}
void* operator new[](std::size_t sz)
{
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs("?\?(?\?)", "UnknownType");
return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None,
@@ -110,6 +121,8 @@ void* operator new[](std::size_t sz)
void* operator new[](std::size_t sz,
const char* funcName, const char* typeName)
{
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs(funcName, typeName);
return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None,
@@ -120,5 +133,10 @@ void* operator new[](std::size_t sz,
void operator delete[](void* ptr) noexcept
{
if (!Retro::g_memoryAllocatorReady)
{
free(ptr);
return;
}
Retro::CMemory::Free(ptr);
}