aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/memalloc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDedicatedTest/memalloc.cpp')
-rw-r--r--NorthstarDedicatedTest/memalloc.cpp41
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