From a3f877daf15ae16a8cf802a9ead10fe9967bc100 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 24 Apr 2014 21:20:14 +0200 Subject: [PATCH] Added MemoryManager::GetAllocationCount() Former-commit-id: 32f4f0780fdd32ac72a7e94732958bdd688844c6 --- include/Nazara/Core/Debug/MemoryManager.hpp | 1 + src/Nazara/Core/Debug/MemoryManager.cpp | 23 ++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/Nazara/Core/Debug/MemoryManager.hpp b/include/Nazara/Core/Debug/MemoryManager.hpp index 9c3677a9d..5aaac72c1 100644 --- a/include/Nazara/Core/Debug/MemoryManager.hpp +++ b/include/Nazara/Core/Debug/MemoryManager.hpp @@ -18,6 +18,7 @@ class NAZARA_API NzMemoryManager static unsigned int GetAllocatedBlockCount(); static std::size_t GetAllocatedSize(); + static unsigned int GetAllocationCount(); static void NextFree(const char* file, unsigned int line); diff --git a/src/Nazara/Core/Debug/MemoryManager.cpp b/src/Nazara/Core/Debug/MemoryManager.cpp index a79854c55..ce5c2eb52 100644 --- a/src/Nazara/Core/Debug/MemoryManager.cpp +++ b/src/Nazara/Core/Debug/MemoryManager.cpp @@ -47,6 +47,8 @@ namespace 0, s_magic }; + + unsigned int s_allocationCount = 0; unsigned int s_allocatedBlock = 0; std::size_t s_allocatedSize = 0; @@ -101,6 +103,7 @@ void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file, s_allocatedBlock++; s_allocatedSize += size; + s_allocationCount++; #if defined(NAZARA_PLATFORM_WINDOWS) LeaveCriticalSection(&s_mutex); @@ -133,20 +136,11 @@ void NzMemoryManager::Free(void* pointer, bool multi) FILE* log = std::fopen(s_MLTFileName, "a"); + const char* error = (multi) ? "delete[] after new" : "delete after new[]"; if (s_nextFreeFile) - { - if (multi) - std::fprintf(log, "%s Warning: delete[] after new at %s:%u\n", timeStr, s_nextFreeFile, s_nextFreeLine); - else - std::fprintf(log, "%s Warning: delete after new[] at %s:%u\n", timeStr, s_nextFreeFile, s_nextFreeLine); - } + std::fprintf(log, "%s Warning: %s at %s:%u\n", timeStr, error, s_nextFreeFile, s_nextFreeLine); else - { - if (multi) - std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", timeStr); - else - std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", timeStr); - } + std::fprintf(log, "%s Warning: %s at unknown position\n", error, timeStr); std::fclose(log); } @@ -180,6 +174,11 @@ std::size_t NzMemoryManager::GetAllocatedSize() return s_allocatedSize; } +unsigned int NzMemoryManager::GetAllocationCount() +{ + return s_allocationCount; +} + void NzMemoryManager::NextFree(const char* file, unsigned int line) { s_nextFreeFile = file;