Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54159 - in sandbox/monotonic: boost/monotonic boost/monotonic/detail libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-21 19:55:47


Author: cschladetsch
Date: 2009-06-21 19:55:47 EDT (Sun, 21 Jun 2009)
New Revision: 54159
URL: http://svn.boost.org/trac/boost/changeset/54159

Log:
added detail/pool.hpp

Added:
   sandbox/monotonic/boost/monotonic/detail/pool.hpp (contents, props changed)
Text files modified:
   sandbox/monotonic/boost/monotonic/config.hpp | 1
   sandbox/monotonic/boost/monotonic/storage.hpp | 44 ++++-----------------------------------
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 4 +++
   3 files changed, 10 insertions(+), 39 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/config.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/config.hpp (original)
+++ sandbox/monotonic/boost/monotonic/config.hpp 2009-06-21 19:55:47 EDT (Sun, 21 Jun 2009)
@@ -20,6 +20,7 @@
                                 MinHeapIncrement = 32*1024*1024, ///< the smallest new chunk-size for heap storage
                                 StaticInlineSize = 1*1024*1024, ///< inline size for a global store. this goes into your BSS
                                 StaticMinHeapIncrement = 32*1024*1024,
+ MinPoolSize = 8,
                         };
                 };
 

Added: sandbox/monotonic/boost/monotonic/detail/pool.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/detail/pool.hpp 2009-06-21 19:55:47 EDT (Sun, 21 Jun 2009)
@@ -0,0 +1,60 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_MONOTONIC_DETAIL_POOL_HPP
+#define BOOST_MONOTONIC_DETAIL_POOL_HPP
+
+namespace boost
+{
+ namespace monotonic
+ {
+ namespace detail
+ {
+ /// a pool of same-sized chunks in a storage block of the given type
+ template <class Storage>
+ struct Pool
+ {
+ char *first, *next, *last;
+ size_t bucket_size;
+ Pool() : first(0), next(0), last(0), bucket_size(0)
+ {
+ }
+ Pool(size_t bs) : first(0), next(0), last(0), bucket_size(bs)
+ {
+ }
+ void *allocate(Storage *storage)
+ {
+ if (next == last)
+ expand(storage);
+ void *ptr = next;
+ next += bucket_size;
+ return ptr;
+ }
+ void expand(Storage *storage)
+ {
+ size_t capacity = std::max(DefaultSizes::MinPoolSize*bucket_size, (last - first)*bucket_size*2);
+ void *ptr = storage->from_fixed(capacity, 16);
+ if (ptr == 0)
+ {
+ ptr = storage->from_heap(capacity, 16);
+ }
+ first = next = (char *)ptr;
+ last = first + capacity;
+ }
+ void reset()
+ {
+ first = next = last = 0;
+ }
+ };
+
+ } // namespace detail
+
+ } // namespace monotonic
+
+} // namespace boost
+
+#endif // BOOST_MONOTONIC_DETAIL_POOL_HPP
+
+//EOF

Modified: sandbox/monotonic/boost/monotonic/storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/storage.hpp 2009-06-21 19:55:47 EDT (Sun, 21 Jun 2009)
@@ -8,6 +8,7 @@
 
 #include <algorithm>
 #include <boost/monotonic/fixed_storage.hpp>
+#include <boost/monotonic/detail/pool.hpp>
 #include <boost/monotonic/detail/link.hpp>
 
 namespace boost
@@ -28,6 +29,7 @@
                         typedef detail::Link<CharAllocator> Link;
                         typedef storage<InlineSize, MinHeapIncrement, Al> This;
                         typedef std::vector<Link> Chain;
+ typedef detail::Pool<This> Pool;
 
                 private:
                         fixed_storage<InlineSize> fixed; // the inline fixed-sized storage which may be on the stack
@@ -35,52 +37,16 @@
                         Allocator alloc; // allocator for heap-based storage
 
                         BOOST_STATIC_CONSTANT(size_t, NumPools = 8);
- BOOST_STATIC_CONSTANT(size_t, MinPoolSize = 8);
                         BOOST_STATIC_CONSTANT(size_t, ChunkShift = 4);
                         BOOST_STATIC_CONSTANT(size_t, ChunkSize = 1 << ChunkShift);
 
- template <class Storage>
- struct Pool
- {
- char *first, *next, *last;
- size_t bucket_size;
- Pool() : first(0), next(0), last(0), bucket_size(0)
- {
- }
- Pool(size_t bs) : first(0), next(0), last(0), bucket_size(bs)
- {
- }
- void *allocate(Storage *storage)
- {
- if (next == last)
- expand(storage);
- void *ptr = next;
- next += bucket_size;
- return ptr;
- }
- void expand(Storage *storage)
- {
- size_t capacity = std::max(MinPoolSize*bucket_size, (last - first)*bucket_size*2);
- void *ptr = storage->from_fixed(capacity, 16);
- if (ptr == 0)
- {
- ptr = storage->from_heap(capacity, 16);
- }
- first = next = (char *)ptr;
- last = first + capacity;
- }
- void reset()
- {
- first = next = last = 0;
- }
- };
- boost::array<Pool<This>, NumPools> pools;
+ boost::array<Pool, NumPools> pools;
 
                         void create_pools()
                         {
                                 for (size_t n = 0; n < NumPools; ++n)
                                 {
- pools[n] = Pool<This>(n*ChunkSize);
+ pools[n] = Pool(n*ChunkSize);
                                 }
                         }
 
@@ -102,7 +68,7 @@
                         void reset()
                         {
                                 fixed.reset();
- BOOST_FOREACH(Pool<This> &pool, pools)
+ BOOST_FOREACH(Pool&pool, pools)
                                 {
                                         pool.reset();
                                 }

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-06-21 19:55:47 EDT (Sun, 21 Jun 2009)
@@ -357,6 +357,10 @@
                                                 RelativePath="..\..\..\boost\monotonic\detail\link.hpp"
>
                                         </File>
+ <File
+ RelativePath="..\..\..\boost\monotonic\detail\pool.hpp"
+ >
+ </File>
                                 </Filter>
                         </Filter>
                         <Filter


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