diff --git a/src/Core/Memory.cpp b/src/Core/Memory.cpp index 5d3d145..6d5a605 100644 --- a/src/Core/Memory.cpp +++ b/src/Core/Memory.cpp @@ -118,7 +118,7 @@ namespace SparkyStudios::Audio::Amplitude void MemoryManager::Initialize(std::unique_ptr allocator) { - if (gMemManager == nullptr) + if (!IsInitialized()) gMemManager = new MemoryManager(std::move(allocator)); #if !defined(AM_NO_MEMORY_STATS) diff --git a/tests/main.cpp b/tests/main.cpp index 97489ae..ca9704c 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -104,6 +104,27 @@ struct AmTestListener : Catch::EventListenerBase CATCH_REGISTER_LISTENER(AmTestListener) +#if !defined(AM_NO_MEMORY_STATS) +static void printMemoryStats() +{ + std::vector pools = { + eMemoryPoolKind_Amplimix, eMemoryPoolKind_Codec, eMemoryPoolKind_Engine, eMemoryPoolKind_Filtering, + eMemoryPoolKind_SoundData, eMemoryPoolKind_IO, eMemoryPoolKind_Default, + }; + + for (auto&& kind : pools) + { + const auto& stats = amMemory->GetStats(kind); + + std::cout << "Pool Name - " << MemoryManager::GetMemoryPoolName(kind) << std::endl; + std::cout << " Allocations Count: " << stats.allocCount << std::endl; + std::cout << " Frees Count: " << stats.freeCount << std::endl; + std::cout << " Total Memory used: " << stats.maxMemoryUsed << std::endl; + std::cout << std::endl; + } +} +#endif + int main(int argc, char* argv[]) { ConsoleLogger logger; @@ -113,6 +134,12 @@ int main(int argc, char* argv[]) const auto res = Catch::Session().run(argc, argv); +#if !defined(AM_NO_MEMORY_STATS) + printMemoryStats(); + + amLogInfo("%s", amMemory->InspectMemoryLeaks().c_str()); +#endif + MemoryManager::Deinitialize(); return res;