diff options
author | p0358 <p0358@users.noreply.github.com> | 2021-12-30 06:26:10 +0100 |
---|---|---|
committer | p0358 <p0358@users.noreply.github.com> | 2021-12-30 06:26:10 +0100 |
commit | 4f7c3d02943a38941b79a638c5607b2b7f668956 (patch) | |
tree | 57cf52a0fcf5aaebedc7c8340a88038857c50174 /NorthstarDedicatedTest/memalloc.cpp | |
parent | cec11fbdefa6e96cffd635fe0047de5245764cc9 (diff) | |
download | NorthstarLauncher-4f7c3d02943a38941b79a638c5607b2b7f668956.tar.gz NorthstarLauncher-4f7c3d02943a38941b79a638c5607b2b7f668956.zip |
actually use custom allocation, override allocators of curl and rapidjson
Diffstat (limited to 'NorthstarDedicatedTest/memalloc.cpp')
-rw-r--r-- | NorthstarDedicatedTest/memalloc.cpp | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp index d301f1fa..c1fb70e7 100644 --- a/NorthstarDedicatedTest/memalloc.cpp +++ b/NorthstarDedicatedTest/memalloc.cpp @@ -20,7 +20,7 @@ char pStaticAllocBuf[STATIC_ALLOC_SIZE]; // TODO: rename to malloc and free after removing statically compiled .libs -void* malloc_(size_t n) +extern "C" void* _malloc_base(size_t n) { // allocate into static buffer if g_pMemAllocSingleton isn't initialised if (g_pMemAllocSingleton) @@ -41,7 +41,12 @@ void* malloc_(size_t n) } } -void free_(void* p) +/*extern "C" void* malloc(size_t n) +{ + return _malloc_base(n); +}*/ + +extern "C" void _free_base(void* p) { // if it was allocated into the static buffer, just do nothing, safest way to deal with it if (p >= pStaticAllocBuf && p <= pStaticAllocBuf + STATIC_ALLOC_SIZE) @@ -54,7 +59,7 @@ void free_(void* p) g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p); } -void* realloc_(void* old_ptr, size_t size) { +extern "C" void* _realloc_base(void* old_ptr, size_t size) { // it was allocated into the static buffer if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE) { @@ -69,20 +74,42 @@ void* realloc_(void* old_ptr, size_t size) { } else { - return malloc_(size); + return _malloc_base(size); } } if (g_pMemAllocSingleton) return g_pMemAllocSingleton->m_vtable->Realloc(g_pMemAllocSingleton, old_ptr, size); + return nullptr; +} + +extern "C" void* _calloc_base(size_t n, size_t size) +{ + return _malloc_base(n * size); +} + +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_(n); + return _malloc_base(n); } void operator delete(void* p) { - free_(p); -}
\ No newline at end of file + _free_base(p); +}// /FORCE:MULTIPLE
\ No newline at end of file |