Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78350 - in sandbox/pool: boost/pool libs/pool/test
From: svart.riddare_at_[hidden]
Date: 2012-05-06 09:29:41


Author: edupuis
Date: 2012-05-06 09:29:40 EDT (Sun, 06 May 2012)
New Revision: 78350
URL: http://svn.boost.org/trac/boost/changeset/78350

Log:
Added new get_size() member function for pool, static_pool and object_pool. This fixes #6865.
Added:
   sandbox/pool/libs/pool/test/test_bug_6865.cpp (contents, props changed)
Text files modified:
   sandbox/pool/boost/pool/object_pool.hpp | 5 +++++
   sandbox/pool/boost/pool/pool.hpp | 10 ++++++++++
   sandbox/pool/boost/pool/static_pool.hpp | 5 +++++
   3 files changed, 20 insertions(+), 0 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-06 09:29:40 EDT (Sun, 06 May 2012)
@@ -321,6 +321,11 @@
     { //! Set max_size.
       pool<UserAllocator>::set_max_size(nmax_size);
     }
+
+ size_type get_size() const
+ {
+ return pool<UserAllocator>::get_size();
+ }
 };
 
 /*! \brief A template class

Modified: sandbox/pool/boost/pool/pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/pool.hpp (original)
+++ sandbox/pool/boost/pool/pool.hpp 2012-05-06 09:29:40 EDT (Sun, 06 May 2012)
@@ -427,6 +427,16 @@
       //! (This value will not change during the lifetime of a Pool object).
       return requested_size;
     }
+ size_type get_size() const
+ { //! \returns the total number of chunks (allocated or not) currently held by this pool
+ size_type partition_size = alloc_size();
+ size_type size = 0;
+
+ for (details::PODptr<size_type> podptr = list; podptr.valid(); podptr = podptr.next())
+ size += podptr.element_size() / partition_size;
+
+ return size;
+ }
 
     // Both malloc and ordered_malloc do a quick inlined check first for any
     // free chunks. Only if we need to get another memory block do we call

Modified: sandbox/pool/boost/pool/static_pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/static_pool.hpp (original)
+++ sandbox/pool/boost/pool/static_pool.hpp 2012-05-06 09:29:40 EDT (Sun, 06 May 2012)
@@ -87,6 +87,11 @@
     {
       return pool<UserAllocator>::get_requested_size();
     }
+
+ size_type get_size() const
+ {
+ return pool<UserAllocator>::get_size();
+ }
        
     bool is_from(void * const chunk) const
     {

Added: sandbox/pool/libs/pool/test/test_bug_6865.cpp
==============================================================================
--- (empty file)
+++ sandbox/pool/libs/pool/test/test_bug_6865.cpp 2012-05-06 09:29:40 EDT (Sun, 06 May 2012)
@@ -0,0 +1,48 @@
+/* Copyright (C) 2012 Étienne Dupuis
+*
+* Use, modification and distribution is subject to the
+* Boost Software License, Version 1.0. (See accompanying
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+// Test of ticket #6865 (https://svn.boost.org/trac/boost/ticket/6865)
+// Implementation of pool::get_size()
+
+#include <boost/pool/pool.hpp>
+#include <boost/pool/static_pool.hpp>
+#include <boost/pool/object_pool.hpp>
+
+int main()
+{
+ // Test pool
+ for (int nSize = 1; nSize < 128; nSize = 2 * nSize + 1)
+ {
+ boost::pool<> p(nSize, 4);
+ p.malloc();
+
+ BOOST_ASSERT(p.get_size() == 4);
+
+ for (int k = 0; k < 4; k++)
+ p.malloc();
+
+ BOOST_ASSERT(p.get_size() == 4 + 8);
+
+ p.purge_memory();
+ BOOST_ASSERT(p.get_size() == 0);
+
+ p.malloc();
+ BOOST_ASSERT(p.get_size() == 4);
+ }
+
+ // Test static_pool
+ boost::static_pool<> sp(sizeof(int), 48);
+ BOOST_ASSERT(sp.get_size() == 48);
+
+ // Test object_pool
+ boost::object_pool<int> op(32);
+
+ op.malloc();
+ BOOST_ASSERT(op.get_size() == 32);
+
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk