Salome HOME
Merge from V6_main 11/02/2013
[modules/smesh.git] / src / SMDS / ObjectPool.hxx
index 1ee3710556b2804591e9eb086455142911367455..261ed6459b574aadcfba86b21aa84bc0a7647b21 100644 (file)
 #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
 {
 
@@ -70,7 +79,7 @@ public:
 
   virtual ~ObjectPool()
   {
-    for (int i = 0; i < _chunkList.size(); i++)
+    for (size_t i = 0; i < _chunkList.size(); i++)
       delete[] _chunkList[i];
   }
 
@@ -101,7 +110,7 @@ public:
   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);
@@ -121,6 +130,16 @@ public:
       }
   }
 
+  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()