Use placement new to initalise objects
This commit is contained in:
parent
5a76eab4c0
commit
6991c2dd84
@ -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();
|
m_FreeList.pop_front();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
void Free(T* ptr)
|
void Free(T* ptr)
|
||||||
{
|
{
|
||||||
|
// placement destruct.
|
||||||
|
ptr->~T();
|
||||||
m_FreeList.push_front(ptr);
|
m_FreeList.push_front(ptr);
|
||||||
if (m_FreeList.size() == BufferSize)
|
if (m_FreeList.size() == BufferSize)
|
||||||
{
|
{
|
||||||
@ -50,5 +53,5 @@ class AllocationPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<T*> m_FreeList;
|
std::list<void *> m_FreeList;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user