pool: add clear function
This commit is contained in:
parent
ab0bb60602
commit
bdbcb0788d
17
pool.hpp
17
pool.hpp
@ -77,10 +77,7 @@ namespace cruft {
|
|||||||
// allocate the memory and note the base address for deletion in destructor
|
// allocate the memory and note the base address for deletion in destructor
|
||||||
m_next = m_head = new node[m_capacity];
|
m_next = m_head = new node[m_capacity];
|
||||||
|
|
||||||
// build out a complete singly linked list from all the nodes.
|
clear ();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~pool ()
|
~pool ()
|
||||||
@ -161,6 +158,18 @@ namespace cruft {
|
|||||||
bool full (void) const { return size () == capacity (); }
|
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
|
// Indexing
|
||||||
size_t index (T const *ptr) const
|
size_t index (T const *ptr) const
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user