pool: add clear function

This commit is contained in:
Danny Robson 2019-05-22 15:05:10 +10:00
parent ab0bb60602
commit bdbcb0788d

View File

@ -77,10 +77,7 @@ namespace cruft {
// allocate the memory and note the base address for deletion in destructor
m_next = m_head = new node[m_capacity];
// build out a complete singly linked list from all the nodes.
for (size_t i = 0; i < m_capacity - 1; ++i)
m_next[i].next = m_next + i + 1;
m_next[m_capacity - 1].next = nullptr;
clear ();
}
~pool ()
@ -161,6 +158,18 @@ namespace cruft {
bool full (void) const { return size () == capacity (); }
void clear (void)
{
m_next = m_head;
// build out a complete singly linked list from all the nodes.
for (size_t i = 0; i < m_capacity - 1; ++i)
m_next[i].next = m_next + i + 1;
m_next[m_capacity - 1].next = nullptr;
}
// Indexing
size_t index (T const *ptr) const
{