From 6991c2dd84060f8e7375966d4e488a359b42d43a Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 15:48:09 +0100 Subject: Use placement new to initalise objects --- src/AllocationPool.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/AllocationPool.h') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f1e324953..d14d56f7a 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -36,12 +36,15 @@ class AllocationPool { } } } - T* ret = m_FreeList.front(); + // placement new, used to initalize the object + T* ret = new (m_FreeList.front()) T; m_FreeList.pop_front(); return ret; } void Free(T* ptr) { + // placement destruct. + ptr->~T(); m_FreeList.push_front(ptr); if (m_FreeList.size() == BufferSize) { @@ -50,5 +53,5 @@ class AllocationPool { } private: - std::list m_FreeList; + std::list m_FreeList; } -- cgit v1.2.3