diff --git a/pool.hpp b/pool.hpp index 4be5b764..b16689b3 100644 --- a/pool.hpp +++ b/pool.hpp @@ -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 {