From 75dcea40f2399c6d91e2307dcde9252043eec36a Mon Sep 17 00:00:00 2001 From: William Moberg Date: Tue, 1 Dec 2015 17:29:26 +0100 Subject: [PATCH] Log warning when memory is exceeded in MemoryPool. --- include/Engine/Core/MemoryPool.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/include/Engine/Core/MemoryPool.h b/include/Engine/Core/MemoryPool.h index 8fba0845..246f7d0a 100644 --- a/include/Engine/Core/MemoryPool.h +++ b/include/Engine/Core/MemoryPool.h @@ -1,6 +1,6 @@ #ifndef MemoryPool_h__ #define MemoryPool_h__ -#include +#include "Common.h" template class MemoryPoolForwardIterator; @@ -57,18 +57,6 @@ public: , m_LowestAllocatedSlot(m_NumSlots) { } - MemoryPool(size_t numMaxElements, size_t stride, char* allocatedMemory) - : m_StartAddress(allocatedMemory) - , m_SlotIsAllocated(numMaxElements, false) - , m_NumSlots(numMaxElements) - , m_Stride(stride) - , m_NumAllocatedSlots(0) - , m_CurrentAllocSlot(0) - , m_LowestAllocatedSlot(m_NumSlots) - { } - - - //We may get problems with memory being released //prematurely, etc. if we allow copies. MemoryPool(const MemoryPool& other) = delete; @@ -98,11 +86,13 @@ public: //Mark the slot as allocated. m_SlotIsAllocated[m_CurrentAllocSlot] = true; ++m_NumAllocatedSlots; + //Also increment slot to allocate. return m_StartAddress + m_Stride*m_CurrentAllocSlot++; } else { m_ExtraMemory.push_back((char*)malloc(m_Stride)); - //TODO: Log this later, we should preferably never enter here, set more memory in constructor instead. + //We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead. + LOG_WARNING("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size()); return m_ExtraMemory.back(); } }