Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53859 - sandbox/monotonic/boost/monotonic
From: christian.schladetsch_at_[hidden]
Date: 2009-06-13 03:47:39


Author: cschladetsch
Date: 2009-06-13 03:47:39 EDT (Sat, 13 Jun 2009)
New Revision: 53859
URL: http://svn.boost.org/trac/boost/changeset/53859

Log:
using boost::aligned_storage to determine correct mask

Text files modified:
   sandbox/monotonic/boost/monotonic/allocator.h | 24 ++++++++++++++++++++----
   sandbox/monotonic/boost/monotonic/inline_storage.h | 6 +++++-
   2 files changed, 25 insertions(+), 5 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/allocator.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.h (original)
+++ sandbox/monotonic/boost/monotonic/allocator.h 2009-06-13 03:47:39 EDT (Sat, 13 Jun 2009)
@@ -7,13 +7,17 @@
 
 #include <boost/monotonic/storage_base.h>
 #include <boost/monotonic/inline_storage.h>
+#include <boost/assert.hpp>
+#include <boost/swap.hpp>
+#include <boost/type_traits/has_trivial_constructor.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
 
 namespace boost
 {
         namespace monotonic
         {
                 /// forward declaration
- template <class T>
+ template <class>
                 class allocator;
 
                 /// specialization for void
@@ -95,7 +99,8 @@
 
                         pointer allocate(size_type num, allocator<void>::const_pointer hint = 0)
                         {
- assert(num > 0);
+ BOOST_ASSERT(num > 0);
+ BOOST_ASSERT(storage != 0);
                                 return static_cast<T *>(storage->allocate(num*sizeof(T), hint));
                         }
 
@@ -106,6 +111,7 @@
 
                         size_type max_size() const throw()
                         {
+ BOOST_ASSERT(storage != 0);
                                 return storage->max_size();
                         }
 
@@ -113,6 +119,7 @@
                         {
                                 new (p) T();
                         }
+
                         void construct(pointer p, const T& val)
                         {
                                 new (p) T(val);
@@ -122,12 +129,21 @@
                         {
                                 if (!p)
                                         return;
- p->T::~T();
+ destroy(p, boost::has_trivial_destructor<T>());
+ }
+
+ void destroy(pointer p, const boost::false_type& )
+ {
+ (*p).~T();
+ }
+
+ void destroy(pointer, const boost::true_type& )
+ {
                         }
 
                         void swap(allocator<T> &other)
                         {
- std::swap(storage, other.storage);
+ boost::swap(storage, other.storage);
                         }
 
                         friend bool operator==(allocator<T> const &A, allocator<T> const &B) { return A.storage == B.storage; }

Modified: sandbox/monotonic/boost/monotonic/inline_storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/inline_storage.h (original)
+++ sandbox/monotonic/boost/monotonic/inline_storage.h 2009-06-13 03:47:39 EDT (Sat, 13 Jun 2009)
@@ -7,6 +7,7 @@
 
 #include <cassert>
 #include <boost/array.hpp>
+#include <boost/aligned_storage.hpp>
 
 // define this to use boost::auto_buffer<> rather than boost::array for monotonic::inline_storage
 //#define BOOST_MONOTONIC_USE_AUTOBUFFER
@@ -25,6 +26,8 @@
                 template <size_t N>
                 struct inline_storage : storage_base
                 {
+ BOOST_STATIC_CONSTANT(size_t, mask = boost::aligned_storage<1>::alignment - 1);
+
 #ifdef BOOST_MONOTONIC_USE_AUTOBUFFER
                         typedef boost::auto_buffer<char, boost::store_n_bytes<N> > buffer_type;
 #else
@@ -59,7 +62,8 @@
                         void *allocate(size_t num_bytes, void const * = 0)
                         {
                                 // ensure we return a point on an aligned boundary
- size_t extra = num_bytes & 15;
+ int n = mask;
+ size_t extra = num_bytes & mask;
                                 size_t required = num_bytes + extra;
 #ifdef BOOST_MONOTONIC_USE_AUTOBUFFER
                                 buffer.uninitialized_resize(buffer.size() + required);


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