diff options
author | Emma Miler <emma.pi@protonmail.com> | 2022-12-19 19:32:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-19 19:32:16 +0100 |
commit | e04f3b36accccb590a2d51b4829256b9964ac3fd (patch) | |
tree | 20ee30c82e6f53e6e772be2e1b9613eebca12bf3 /NorthstarDLL/core/memalloc.cpp | |
parent | 33f18a735986dcd136bf8ba70ad8331306c28227 (diff) | |
download | NorthstarLauncher-e04f3b36accccb590a2d51b4829256b9964ac3fd.tar.gz NorthstarLauncher-e04f3b36accccb590a2d51b4829256b9964ac3fd.zip |
Restructuring (#365)
* Remove launcher proxy
* Restructuring
* More restructuring
* Fix include dirs
* Fix merge
* Remove clang thing
* Filters
* Oops
Diffstat (limited to 'NorthstarDLL/core/memalloc.cpp')
-rw-r--r-- | NorthstarDLL/core/memalloc.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/NorthstarDLL/core/memalloc.cpp b/NorthstarDLL/core/memalloc.cpp new file mode 100644 index 00000000..122ab444 --- /dev/null +++ b/NorthstarDLL/core/memalloc.cpp @@ -0,0 +1,74 @@ +#include "pch.h" +#include "core/memalloc.h" +#include "core/tier0.h" + +using namespace Tier0; + +// TODO: rename to malloc and free after removing statically compiled .libs + +extern "C" void* _malloc_base(size_t n) +{ + // allocate into static buffer if g_pMemAllocSingleton isn't initialised + if (!g_pMemAllocSingleton) + TryCreateGlobalMemAlloc(); + + return g_pMemAllocSingleton->m_vtable->Alloc(g_pMemAllocSingleton, n); +} + +/*extern "C" void* malloc(size_t n) +{ + return _malloc_base(n); +}*/ + +extern "C" void _free_base(void* p) +{ + if (!g_pMemAllocSingleton) + TryCreateGlobalMemAlloc(); + + g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p); +} + +extern "C" void* _realloc_base(void* oldPtr, size_t size) +{ + if (!g_pMemAllocSingleton) + TryCreateGlobalMemAlloc(); + + return g_pMemAllocSingleton->m_vtable->Realloc(g_pMemAllocSingleton, oldPtr, size); +} + +extern "C" void* _calloc_base(size_t n, size_t size) +{ + size_t bytes = n * size; + void* memory = _malloc_base(bytes); + if (memory) + { + memset(memory, 0, bytes); + } + return memory; +} + +extern "C" char* _strdup_base(const char* src) +{ + char* str; + char* p; + int len = 0; + + while (src[len]) + len++; + str = reinterpret_cast<char*>(_malloc_base(len + 1)); + p = str; + while (*src) + *p++ = *src++; + *p = '\0'; + return str; +} + +void* operator new(size_t n) +{ + return _malloc_base(n); +} + +void operator delete(void* p) noexcept +{ + _free_base(p); +} // /FORCE:MULTIPLE |