Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54048 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-18 00:16:38


Author: cschladetsch
Date: 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
New Revision: 54048
URL: http://svn.boost.org/trac/boost/changeset/54048

Log:
storage now uses a heap for links

Text files modified:
   sandbox/monotonic/boost/monotonic/config.hpp | 6 +++---
   sandbox/monotonic/boost/monotonic/storage.hpp | 33 ++++++++++++++++++++++++++-------
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp | 20 ++++++++++++++++----
   sandbox/monotonic/libs/monotonic/test/main.cpp | 1 +
   sandbox/monotonic/libs/monotonic/test/monotonic.sln | 6 ++++++
   sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp | 3 ++-
   6 files changed, 54 insertions(+), 15 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/config.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/config.hpp (original)
+++ sandbox/monotonic/boost/monotonic/config.hpp 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
@@ -15,9 +15,9 @@
                         enum
                         {
                                 InlineSize = 8*1024, ///< buffer that is inline with the storage
- MinHeapIncrement = 2*1024*1024, ///< the smallest new chunk-size for heap storage
- StaticInlineSize = 64*1024, ///< inline size for a global store
- StaticMinHeapIncrement = MinHeapIncrement,
+ MinHeapIncrement = 64*1024*1024, ///< the smallest new chunk-size for heap storage
+ StaticInlineSize = 64*1024, ///< inline size for a global store. this goes into your BSS
+ StaticMinHeapIncrement = 64*1024*1024,
                         };
                 };
 

Modified: sandbox/monotonic/boost/monotonic/storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/storage.hpp 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
@@ -6,6 +6,7 @@
 #ifndef BOOST_MONOTONIC_STORAGE_H
 #define BOOST_MONOTONIC_STORAGE_H
 
+#include <algorithm>
 #include <boost/monotonic/fixed_storage.hpp>
 
 namespace boost
@@ -43,14 +44,14 @@
                                         if (buffer == 0)
                                                 capacity = 0;
                                 }
- ~Link()
- {
- alloc.deallocate(buffer, 1);
- }
                                 void reset()
                                 {
                                     cursor = 0;
                                 }
+ void clear()
+ {
+ alloc.deallocate(buffer, 1);
+ }
                                 size_t used() const
                                 {
                                         return cursor;
@@ -71,8 +72,12 @@
                                         cursor += required;
                                         return ptr + extra;
                                 }
+ friend bool operator<(Link const &A, Link const &B)
+ {
+ return A.capacity < B.capacity;
+ }
                         };
- typedef std::vector<Link, Al> Chain;
+ typedef std::vector<Link, Al> Chain; // maintained a priority-queue
 
                 private:
                         fixed_storage<InlineSize> fixed; // the inline fixed-sized storage which may be on the stack
@@ -87,6 +92,10 @@
                                 : alloc(A)
                         {
                         }
+ ~storage()
+ {
+ release();
+ }
 
                         void reset()
                         {
@@ -100,6 +109,10 @@
                         void release()
                         {
                                 reset();
+ BOOST_FOREACH(Link &link, chain)
+ {
+ link.clear();
+ }
                                 chain.clear();
                         }
 
@@ -109,9 +122,14 @@
                                 {
                                         return ptr;
                                 }
- BOOST_FOREACH(Link &link, chain)
+ if (!chain.empty())
                                 {
- if (void *ptr = link.Allocate(num_bytes, alignment))
+ if (void *ptr = chain.front().Allocate(num_bytes, alignment))
+ {
+ return ptr;
+ }
+ std::make_heap(chain.begin(), chain.end());
+ if (void *ptr = chain.front().Allocate(num_bytes, alignment))
                                         {
                                                 return ptr;
                                         }
@@ -149,6 +167,7 @@
                                 chain.push_back(Link(alloc, size));
                                 Link &link = chain.back();
                                 link.Construct();
+ std::make_heap(chain.begin(), chain.end());
                                 return link;
                         }
                 };

Modified: sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
@@ -24,8 +24,15 @@
 
 PoolResult compare_memory_pool(size_t count, size_t length)
 {
- typedef std::list<int, boost::pool_allocator<int> > pool_v;
- typedef std::list<int, boost::fast_pool_allocator<int> > fast_pool_v;
+ typedef boost::fast_pool_allocator<int,
+ boost::default_user_allocator_new_delete,
+ boost::details::pool::null_mutex> fast_pool_alloc;
+ typedef boost::pool_allocator<int,
+ boost::default_user_allocator_new_delete,
+ boost::details::pool::null_mutex> pool_alloc;
+
+ typedef std::list<int, pool_alloc > pool_v;
+ typedef std::list<int, fast_pool_alloc > fast_pool_v;
         typedef std::list<int, boost::monotonic::allocator<int> > mono_v;
         typedef std::list<int > std_v;
 
@@ -37,7 +44,7 @@
                 for (size_t n = 0; n < count; ++n)
                 {
                         {
- pool_v pool;
+ fast_pool_v pool;
                                 thrash_pool(length, pool);
                         }
                         boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(int)>::release_memory();
@@ -98,7 +105,12 @@
         
         typedef std::map<size_t, PoolResult> Results;
         Results results;
- for (size_t length = 10; length < max_length; length += 500)
+ results[5] = compare_memory_pool(count*10, 5);
+ results[20] = compare_memory_pool(count*10, 20);
+ results[50] = compare_memory_pool(count*10, 50);
+ results[100] = compare_memory_pool(count*10, 100);
+
+ for (size_t length = 10; length < max_length; length += 1000)
         {
                 results[length] = compare_memory_pool(count, length);
         }

Modified: sandbox/monotonic/libs/monotonic/test/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/main.cpp 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
@@ -405,6 +405,7 @@
         _set_se_translator(straight_to_debugger);
 #endif
 
+ //test_chained_storage();
         compare_memory_pool();
         //test_mono_map();
         //test_mono_map();

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.sln
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.sln (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.sln 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
@@ -3,6 +3,8 @@
 # Visual Studio 2008
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "monotonic", "monotonic.vcproj", "{5688980A-015B-4C7D-8D8D-F5894205FACE}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PoolTime", "PoolTime\PoolTime.vcproj", "{470832FD-33D6-4F31-AD06-BB7838371077}"
+EndProject
 Global
         GlobalSection(SolutionConfigurationPlatforms) = preSolution
                 Debug|Win32 = Debug|Win32
@@ -13,6 +15,10 @@
                 {5688980A-015B-4C7D-8D8D-F5894205FACE}.Debug|Win32.Build.0 = Debug|Win32
                 {5688980A-015B-4C7D-8D8D-F5894205FACE}.Release|Win32.ActiveCfg = Release|Win32
                 {5688980A-015B-4C7D-8D8D-F5894205FACE}.Release|Win32.Build.0 = Release|Win32
+ {470832FD-33D6-4F31-AD06-BB7838371077}.Debug|Win32.ActiveCfg = Debug|Win32
+ {470832FD-33D6-4F31-AD06-BB7838371077}.Debug|Win32.Build.0 = Debug|Win32
+ {470832FD-33D6-4F31-AD06-BB7838371077}.Release|Win32.ActiveCfg = Release|Win32
+ {470832FD-33D6-4F31-AD06-BB7838371077}.Release|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE

Modified: sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp 2009-06-18 00:16:36 EDT (Thu, 18 Jun 2009)
@@ -3,11 +3,12 @@
 
 void test_chained_storage()
 {
- monotonic::storage<0> store;
+ monotonic::storage<0, 16> store;
         {
                 typedef std::vector<char, monotonic::allocator<char> > Vector;
                 Vector vec(store);
                 vec.resize(5); // still on the stack
+ vec.resize(32); // now on the heap
                 vec.resize(500); // now on the heap
         }
 }


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