Proper string handling without nasty memory leaks. PHEW.

This commit is contained in:
2016-02-19 14:37:14 +01:00
parent ca907b912e
commit 881ce7b02f
8 changed files with 144 additions and 24 deletions
+8 -6
View File
@@ -68,12 +68,13 @@ public:
MemoryPool(const MemoryPool<T>& other)
: m_StartAddress(new char[other.m_NumSlots*other.m_Stride])
, m_SlotIsAllocated(other.m_NumSlots, false)
, m_SlotIsAllocated(other.m_SlotIsAllocated)
, m_ExtraMemory()
, m_NumSlots(other.m_NumSlots)
, m_LowestAllocatedSlot(other.m_LowestAllocatedSlot)
, m_NumAllocatedSlots(other.m_NumAllocatedSlots)
, m_Stride(other.m_Stride)
, m_NumAllocatedSlots(0)
, m_CurrentAllocSlot(0)
, m_LowestAllocatedSlot(m_NumSlots)
, m_CurrentAllocSlot(other.m_CurrentAllocSlot)
{
// Copy statically allocated pool
memcpy(m_StartAddress, other.m_StartAddress, m_NumSlots*m_Stride);
@@ -93,8 +94,9 @@ public:
delete[] m_StartAddress;
m_StartAddress = nullptr;
}
for (char* addr : m_ExtraMemory)
free(addr);
for (char* addr : m_ExtraMemory) {
free(addr);
}
m_ExtraMemory.clear();
}