$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r78454 - sandbox/pool/boost/pool
From: svart.riddare_at_[hidden]
Date: 2012-05-13 12:41:26
Author: edupuis
Date: 2012-05-13 12:41:26 EDT (Sun, 13 May 2012)
New Revision: 78454
URL: http://svn.boost.org/trac/boost/changeset/78454
Log:
Added methods release_memory() and purge_memory() to object_pool. This complete and fixes #6610, as the remaining part of this ticket was addressed by #3789.
Text files modified: 
   sandbox/pool/boost/pool/object_pool.hpp |   124 ++++++++++++++++++++++++--------------- 
   1 files changed, 75 insertions(+), 49 deletions(-)
Modified: sandbox/pool/boost/pool/object_pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/object_pool.hpp	(original)
+++ sandbox/pool/boost/pool/object_pool.hpp	2012-05-13 12:41:26 EDT (Sun, 13 May 2012)
@@ -99,7 +99,17 @@
       allocated = 0;
     }
 
-    ~object_pool_base();
+    ~object_pool_base()
+    {
+      purge_memory();
+    }
+
+    bool release_memory()
+    {
+      return Pool::release_memory();
+    }
+
+    bool purge_memory();
 
     // Returns 0 if out-of-memory.
     element_type * malloc BOOST_PREVENT_MACRO_SUBSTITUTION()
@@ -140,6 +150,11 @@
       return store().is_from(chunk);
     }
 
+    size_type get_size() const
+    {
+      return store().get_size();
+    }
+
     element_type * construct()
     { //! \returns A pointer to an object of type T, allocated in memory from the underlying pool
       //! and default constructed.  The returned objected can be freed by a call to \ref destroy.
@@ -211,62 +226,56 @@
 };
 
 template <typename T, typename Pool>
-object_pool_base<T, Pool>::~object_pool_base()
+bool object_pool_base<T, Pool>::purge_memory()
 {
   // handle trivial case of invalid list.
   if (!this->list.valid())
-    return;
-
-  // do not do useless work
-  if (!allocated)
-    return;
-
-  // sort store
-  store().order();
+    return false;
 
-  details::PODptr<size_type> iter = this->list;
-  details::PODptr<size_type> next = iter;
+  // delete all objects that are not freed
+  if (allocated)
+  {
+    // sort store
+    store().order();
 
-  // Start 'freed_iter' at beginning of free list
-  void * freed_iter = this->first;
+    details::PODptr<size_type> iter = this->list;
+    details::PODptr<size_type> next = iter;
 
-  const size_type partition_size = this->alloc_size();
+    // Start 'freed_iter' at beginning of free list
+    void * freed_iter = this->first;
 
-  do
-  {
-    // increment next
-    next = next.next();
+    const size_type partition_size = this->alloc_size();
 
-    // delete all contained objects that aren't freed.
-
-    // Iterate 'i' through all chunks in the memory block.
-    for (char * i = iter.begin(); i != iter.end(); i += partition_size)
+    do
     {
-      // If this chunk is free,
-      if (i == freed_iter)
-      {
-        // Increment freed_iter to point to next in free list.
-        freed_iter = nextof(freed_iter);
+      // increment next
+      next = next.next();
 
-        // Continue searching chunks in the memory block.
-        continue;
+      // Iterate 'i' through all chunks in the memory block.
+      for (char * i = iter.begin(); i != iter.end(); i += partition_size)
+      {
+        // If this chunk is free,
+        if (i == freed_iter)
+        {
+          // Increment freed_iter to point to next in free list.
+          freed_iter = nextof(freed_iter);
+
+          // Continue searching chunks in the memory block.
+          continue;
+        }
+
+        // This chunk is not free (allocated), so call its destructor,
+        static_cast<T *>(static_cast<void *>(i))->~T();
+        // and continue searching chunks in the memory block.
       }
 
-      // This chunk is not free (allocated), so call its destructor,
-      static_cast<T *>(static_cast<void *>(i))->~T();
-      // and continue searching chunks in the memory block.
-    }
-
-    // free storage.
-    (Pool::free)(iter.begin());
-
-    // increment iter.
-    iter = next;
-  } while (iter.valid());
+      // increment iter.
+      iter = next;
+    } while (iter.valid());
+  }
 
-  // Make the block list empty so that the inherited destructor doesn't try to
-  // free it again.
-  this->list.invalidate();
+  // Call inherited purge function
+  return Pool::purge_memory();
 }
 
 /*! \brief A template class
@@ -340,11 +349,6 @@
     { //! Set max_size.
       pool<UserAllocator>::set_max_size(nmax_size);
     }
-
-    size_type get_size() const
-    {
-      return pool<UserAllocator>::get_size();
-    }
 };
 
 /*! \brief A template class
@@ -387,6 +391,17 @@
       //! \param arg_requested_objects Number of memory chunks to allocate at initialization. 
       //!  It defines the maximum number of objects that can be malloc'ed from this pool.
     }
+
+  protected :
+    bool release_memory()
+    {
+      return false;
+    }
+
+    bool purge_memory()
+    {
+      return false;
+    }
 };
 
 /*! \brief A template class
@@ -427,6 +442,17 @@
     object_pool_base<T, array_pool<sizeof(T), PoolSize> >(PoolSize)
     { //! Constructs a new (empty by default) ArrayObjectPool.
     }
+
+  protected :
+    bool release_memory()
+    {
+      return false;
+    }
+
+    bool purge_memory()
+    {
+      return false;
+    }
 };
 
 } // namespace boost