#define _OBJECTPOOL_HXX_
#include <vector>
-#include <stack>
+//#include <stack>
#include <iostream>
+namespace
+{
+ // assure deallocation of memory of a vector
+ template<class Y> void clearVector(std::vector<Y>& v )
+ {
+ std::vector<Y> emptyVec; v.swap( emptyVec );
+ }
+}
+
template<class X> class ObjectPool
{
virtual ~ObjectPool()
{
- for (int i = 0; i < _chunkList.size(); i++)
+ for (size_t i = 0; i < _chunkList.size(); i++)
delete[] _chunkList[i];
}
void destroy(X* obj)
{
long adrobj = (long) (obj);
- for (int i = 0; i < _chunkList.size(); i++)
+ for (size_t i = 0; i < _chunkList.size(); i++)
{
X* chunk = _chunkList[i];
long adrmin = (long) (chunk);
}
}
+ void clear()
+ {
+ _nextFree = 0;
+ _maxAvail = 0;
+ for (size_t i = 0; i < _chunkList.size(); i++)
+ delete[] _chunkList[i];
+ clearVector( _chunkList );
+ clearVector( _freeList );
+ }
+
// void destroy(int toFree)
// {
// // no control 0<= toFree < _freeList.size()