aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/memalloc.cpp
diff options
context:
space:
mode:
authorp0358 <p0358@users.noreply.github.com>2021-12-30 02:58:19 +0100
committerp0358 <p0358@users.noreply.github.com>2021-12-30 02:58:19 +0100
commitd2ee389192aa425ef9c81b2c3367ffb0de6976d0 (patch)
treef244033f6d85055ca272f8369942969848d053f5 /NorthstarDedicatedTest/memalloc.cpp
parentc18b293ba739424bee6db39e2e5a3081b0010a13 (diff)
downloadNorthstarLauncher-d2ee389192aa425ef9c81b2c3367ffb0de6976d0.tar.gz
NorthstarLauncher-d2ee389192aa425ef9c81b2c3367ffb0de6976d0.zip
Refactor and fix of various issues, add run_northstar.txt support
Diffstat (limited to 'NorthstarDedicatedTest/memalloc.cpp')
-rw-r--r--NorthstarDedicatedTest/memalloc.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp
index 113f56b9..cff0ecac 100644
--- a/NorthstarDedicatedTest/memalloc.cpp
+++ b/NorthstarDedicatedTest/memalloc.cpp
@@ -17,24 +17,48 @@ const int STATIC_ALLOC_SIZE = 100000; // alot more than we need, could reduce to
size_t g_iStaticAllocated = 0;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
-void* operator new(size_t n)
+// TODO: rename to malloc and free after removing statically compiled .libs
+
+void* malloc_(size_t n)
{
// allocate into static buffer if g_pMemAllocSingleton isn't initialised
if (g_pMemAllocSingleton)
+ {
+ //printf("Northstar malloc (g_pMemAllocSingleton): %llu\n", n);
return g_pMemAllocSingleton->m_vtable->Alloc(g_pMemAllocSingleton, n);
+ }
else
{
+ if (g_iStaticAllocated + n > STATIC_ALLOC_SIZE)
+ {
+ throw "Ran out of prealloc space"; // we could log, but spdlog probably does use allocations as well...
+ }
+ //printf("Northstar malloc (prealloc): %llu\n", n);
void* ret = pStaticAllocBuf + g_iStaticAllocated;
g_iStaticAllocated += n;
return ret;
- }
+ }
}
-void operator delete(void* p)
+void free_(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)
+ {
+ //printf("Northstar free (prealloc): %p\n", p);
return;
+ }
+ //printf("Northstar free (g_pMemAllocSingleton): %p\n", p);
g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p);
+}
+
+void* operator new(size_t n)
+{
+ return malloc_(n);
+}
+
+void operator delete(void* p)
+{
+ free_(p);
} \ No newline at end of file