20 #ifndef PTR_LINKED_POOL_IMPL_H 21 #define PTR_LINKED_POOL_IMPL_H 23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 27 #ifndef PTR_LINKED_POOL_H 28 #include "SheafSystem/ptr_linked_pool.h" 31 #ifndef ASSERT_CONTRACT_H 32 #include "SheafSystem/assert_contract.h" 36 #include "SheafSystem/block.impl.h" 40 #include "SheafSystem/std_iomanip.h" 62 return _capacity - _free_size;
82 define_old_variable(
size_t old_allocated_size = allocated_size());
96 _free_list = result->next();
108 ensure(allocated_size() == old_allocated_size + 1);
115 template <
typename T>
123 require(xobject != 0);
124 require(unexecutable(
"xobject is allocated"));
128 define_old_variable(
size_t old_free_size = _free_size);
129 define_old_variable(
size_t old_allocated_size = allocated_size());
131 xobject->put_next(_free_list);
132 _free_list = xobject;
137 ensure(free_size() == old_free_size + 1);
138 ensure(allocated_size() == old_allocated_size - 1);
143 template <
typename T>
152 template <
typename T>
163 xos <<
" capacity: " << capacity()
164 <<
" free_size: " << free_size()
165 <<
" allocated_size: " << allocated_size()
169 xos <<
"pool contents: " << endl;
171 for(citr = _chunk_list.
begin(); citr != _chunk_list.
end(); ++citr)
173 for(
size_t i=0; i<(*citr)->ct(); ++i)
175 xos <<
" " << (*citr)->item(i);
193 template <
typename T>
210 ensure(free_size() == xcapacity);
211 ensure(allocated_size() == 0);
218 template <
typename T>
225 template <
typename T>
233 require(xcapacity > 0);
237 define_old_variable(
size_t old_free_size = _free_size);
239 size_t old_capacity = _capacity;
241 if(xcapacity > _capacity)
245 size_t lchunk_size = xcapacity - old_capacity;
247 lchunk->
set_ct(lchunk_size);
248 _chunk_list.push_front(lchunk);
252 T* lptr = lchunk->
base();
253 for(
size_t i=0; i<(lchunk_size-1); ++i)
255 T* lnext_ptr = lptr+1;
256 lptr->put_next(lnext_ptr);
268 _free_list = lchunk->
base();
277 while(lptr->next() != 0)
282 assertion((lptr != 0) && (lptr->next() == 0));
286 lptr->put_next(lchunk->
base());
291 _free_size += lchunk_size;
292 _capacity += lchunk_size;
297 ensure(capacity() >= xcapacity);
298 ensure(free_size() >= old_free_size);
306 template <
typename T>
318 while(!_chunk_list.empty())
320 block<T>* lchunk = _chunk_list.front();
322 _chunk_list.pop_front();
331 ensure(capacity() == 0);
332 ensure(free_size() == 0);
333 ensure(allocated_size() == 0);
344 template <
typename T>
346 operator<< (std::ostream& xos, const ptr_linked_pool<T>& xp)
363 #endif // ifndef PTR_LINKED_POOL_IMPL_H void reserve(size_t xcapacity)
Makes capacity at least xcapacity.
void clear()
Deletes all the objects in the pool.
size_t capacity() const
The number of objects, either free or allocated, currently in the pool.
T * allocate()
Allocate next available object from the free list.
size_t allocated_size() const
The size of allocated list.
ptr_linked_pool(size_t xcapacity=1024)
Creates an instance with capacity xcapacity.
iterator begin()
Returns an iterator to the first element of the container.
~ptr_linked_pool()
Destructor.
void deallocate(T *xobject)
Deallocate xobject.
void print() const
Prints the data members of this on cout. Intended for use debugging.
pointer_type base() const
The underlying storage array.
void set_ct(size_type xct)
Sets ct() == xct.
iterator end()
Returns an iterator to the element following the last element of the container.
Namespace for the sheaves component of the sheaf system.
size_t free_size() const
The size of free list.
An auto_block with a no-initialization initialization policy.
Wrapper class for forward_list or slist depending on compiler. The class replicates the minimum subse...