aboutsummaryrefslogtreecommitdiff
path: root/primedev/core/memalloc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'primedev/core/memalloc.cpp')
-rw-r--r--primedev/core/memalloc.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/primedev/core/memalloc.cpp b/primedev/core/memalloc.cpp
index 0a75bc2b..51167717 100644
--- a/primedev/core/memalloc.cpp
+++ b/primedev/core/memalloc.cpp
@@ -3,7 +3,7 @@
// TODO: rename to malloc and free after removing statically compiled .libs
-extern "C" void* _malloc_base(size_t n)
+void* _malloc_base(size_t n)
{
// allocate into static buffer if g_pMemAllocSingleton isn't initialised
if (!g_pMemAllocSingleton)
@@ -17,7 +17,7 @@ extern "C" void* _malloc_base(size_t n)
return _malloc_base(n);
}*/
-extern "C" void _free_base(void* p)
+void _free_base(void* p)
{
if (!g_pMemAllocSingleton)
TryCreateGlobalMemAlloc();
@@ -25,7 +25,7 @@ extern "C" void _free_base(void* p)
g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p);
}
-extern "C" void* _realloc_base(void* oldPtr, size_t size)
+void* _realloc_base(void* oldPtr, size_t size)
{
if (!g_pMemAllocSingleton)
TryCreateGlobalMemAlloc();
@@ -33,7 +33,7 @@ extern "C" void* _realloc_base(void* oldPtr, size_t size)
return g_pMemAllocSingleton->m_vtable->Realloc(g_pMemAllocSingleton, oldPtr, size);
}
-extern "C" void* _calloc_base(size_t n, size_t size)
+void* _calloc_base(size_t n, size_t size)
{
size_t bytes = n * size;
void* memory = _malloc_base(bytes);
@@ -44,7 +44,33 @@ extern "C" void* _calloc_base(size_t n, size_t size)
return memory;
}
-extern "C" char* _strdup_base(const char* src)
+void* _recalloc_base(void* const block, size_t const count, size_t const size)
+{
+ if (!block)
+ return _calloc_base(count, size);
+
+ const size_t new_size = count * size;
+ const size_t old_size = _msize(block);
+
+ void* const memory = _realloc_base(block, new_size);
+
+ if (memory && old_size < new_size)
+ {
+ memset(static_cast<char*>(memory) + old_size, 0, new_size - old_size);
+ }
+
+ return memory;
+}
+
+size_t _msize(void* const block)
+{
+ if (!g_pMemAllocSingleton)
+ TryCreateGlobalMemAlloc();
+
+ return g_pMemAllocSingleton->m_vtable->GetSize(g_pMemAllocSingleton, block);
+}
+
+char* _strdup_base(const char* src)
{
char* str;
char* p;