School project / Fall 2025
Memory tracker and plugins
Two engine projects in C++ for Game Engines 5.

Engines need to know where their memory goes, and they often load code that isn't built into the game.
I wrote a memory tracker that counts every allocation and tells you at the end if anything leaked, and hooked it into my A* game. I also made a demo that loads a plugin while the program runs and calls its functions, from C++ and from Python.
- Wrote a memory tracker that counts every allocation and free, and how many bytes are still in use.
- Replaced C++'s new and delete so they report to the tracker while tracking is on. That keeps startup and shutdown out of the numbers.
- Hooked it into my A* game. It prints a summary at the end and says whether anything leaked.
- Made a plugin with four functions, and a program that loads it while running, finds the functions by name and calls them.
- Called the same plugin from Python.
What it caught
On a normal run of my A* game it counted 413 allocations and 412 frees, and flagged one 104 byte block still in use when the game closed.
Not counting itself
The tracker keeps a list of every block, and adding to that list uses memory too. A flag stops it from tracking its own allocations, which would otherwise loop forever.
Loading a plugin
The program loads the plugin file, asks for each function by name and checks it found all four before calling them. If one is missing, it reports an error instead of crashing.
Code I wrote
Short parts of my own code from this project. I left out anything the course gave us.
The memory tracker
MemoryTracker.cpp, C++
// Guard to prevent recursion when the tracker itself allocates memory.
// Also keep a flag to tell us when tracking is active.
namespace
{
std::atomic<bool> g_trackingEnabled{ false };
thread_local bool g_inInternalAllocation = false;
}
// ...
void MemoryTracker::registerAllocation(void* ptr, std::size_t size)
{
if (!g_trackingEnabled.load(std::memory_order_acquire))
return;
if (g_inInternalAllocation)
return;
g_inInternalAllocation = true;
internalRegisterAllocation(ptr, size);
g_inInternalAllocation = false;
}
// ...
void* operator new(std::size_t size)
{
if (size == 0)
size = 1;
void* ptr = std::malloc(size);
if (!ptr)
throw std::bad_alloc();
if (g_trackingEnabled.load(std::memory_order_acquire))
{
MemoryTracker::instance().registerAllocation(ptr, size);
}
return ptr;
}
Loading the plugin
main.cpp, C++
static std::wstring LoadPluginAndBuildOutput()
{
std::wstringstream ss;
// Put PluginDLL.dll next to the HostApp.exe OR copy it there as a post-build step
std::wstring dllPath = GetExeDir() + L"PluginDLL.dll";
gDll = LoadLibraryW(dllPath.c_str());
if (!gDll)
{
DWORD err = GetLastError();
ss << L"[ERROR] LoadLibrary failed\n";
ss << L"Path: " << dllPath << L"\n";
ss << L"GetLastError: " << err << L"\n";
return ss.str();
}
pGetPluginName = (GetPluginNameFn)GetProcAddress(gDll, "GetPluginName");
pAddInts = (AddIntsFn)GetProcAddress(gDll, "AddInts");
pGetMagicNumber = (GetMagicNumberFn)GetProcAddress(gDll, "GetMagicNumber");
pMultiply = (MultiplyFn)GetProcAddress(gDll, "Multiply");
if (!pGetPluginName || !pAddInts || !pGetMagicNumber || !pMultiply)
// ...
const char* name = pGetPluginName();
int sum = pAddInts(2, 3);
float pi = pGetMagicNumber();
float mul = pMultiply(2.5f, 4.0f);
ss << L"[INFO] TOPIC 10: DLL Runtime Loading\n";
ss << L"DLL Path: " << dllPath << L"\n\n";
ss << L"PluginName: " << Widen(name) << L"\n";
ss << L"AddInts(2,3) = " << sum << L"\n";
ss << L"GetMagicNumber() = " << pi << L"\n";
ss << L"Multiply(2.5,4.0) = " << mul << L"\n\n";
// ...
return ss.str();
}
Program output
Console output from running the build. I cut long runs of the same line short.
// Memory tracker, at the end of a run of my A* game
==== Memory Summary ====
Total allocations: 413
Total deallocations: 412
Bytes allocated: 27200
Bytes freed: 27096
Bytes in use: 104
Live blocks: 1
Potential memory leak detected.
========================
// Plugin demo: the C++ host loads PluginDLL.dll and calls its four functions
[INFO] TOPIC 10: DLL Runtime Loading
PluginName: PluginDLL x64
AddInts(2,3) = 5
GetMagicNumber() = 3.14159
Multiply(2.5,4.0) = 10
Status: SUCCESS
// The same plugin from Python (test_plugin.py)
PluginName: PluginDLL x64
AddInts(2, 3): 5
MagicNumber: 3.141590118408203
In 2026 I made two small fixes to get both running again. The tracker had two delete functions defined twice, and the plugin needed the file name the host looks for.
Next school project
Breaking a wall with Chaos
A research project on destruction with Chaos physics in Unreal Engine 5.6.