Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53862 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-13 04:10:10


Author: cschladetsch
Date: 2009-06-13 04:10:08 EDT (Sat, 13 Jun 2009)
New Revision: 53862
URL: http://svn.boost.org/trac/boost/changeset/53862

Log:
now correctly using boost::aligned_storage<sizeof(T)>::alignment

Text files modified:
   sandbox/monotonic/boost/monotonic/allocator.h | 6 ++++--
   sandbox/monotonic/boost/monotonic/inline_storage.h | 6 ++----
   sandbox/monotonic/boost/monotonic/storage_base.h | 6 ++++--
   sandbox/monotonic/libs/monotonic/test/main.cpp | 40 +++++++++++++++++++++++++++++++++++++++-
   4 files changed, 49 insertions(+), 9 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/allocator.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.h (original)
+++ sandbox/monotonic/boost/monotonic/allocator.h 2009-06-13 04:10:08 EDT (Sat, 13 Jun 2009)
@@ -97,11 +97,13 @@
                                 return &x;
                         }
 
- pointer allocate(size_type num, allocator<void>::const_pointer hint = 0)
+ BOOST_STATIC_CONSTANT(size_t, alignment_mask = boost::aligned_storage<sizeof(T)>::alignment - 1);
+
+ pointer allocate(size_type num, allocator<void>::const_pointer /*hint*/ = 0)
                         {
                                 BOOST_ASSERT(num > 0);
                                 BOOST_ASSERT(storage != 0);
- return static_cast<T *>(storage->allocate(num*sizeof(T), hint));
+ return static_cast<T *>(storage->allocate(num*sizeof(T), alignment_mask));
                         }
 
                         void deallocate(pointer p, size_type n)

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 04:10:08 EDT (Sat, 13 Jun 2009)
@@ -26,7 +26,6 @@
                 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;
@@ -58,11 +57,10 @@
                                 cursor = c;
                         }
 
- /// allocate storage. ignore hint.
- void *allocate(size_t num_bytes, void const * = 0)
+ /// allocate storage, given alignment mask
+ void *allocate(size_t num_bytes, size_t mask)
                         {
                                 // ensure we return a point on an aligned boundary
- int n = mask;
                                 size_t extra = num_bytes & mask;
                                 size_t required = num_bytes + extra;
 #ifdef BOOST_MONOTONIC_USE_AUTOBUFFER

Modified: sandbox/monotonic/boost/monotonic/storage_base.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage_base.h (original)
+++ sandbox/monotonic/boost/monotonic/storage_base.h 2009-06-13 04:10:08 EDT (Sat, 13 Jun 2009)
@@ -9,10 +9,12 @@
 {
         namespace monotonic
         {
- /// base structure for inline_storage<N>. should be removed.
+ /// base structure for inline_storage<N>
                 struct storage_base
                 {
- virtual void *allocate(size_t num_bytes, void const *hint = 0) = 0;
+ // the number of bytes to allocate, and the bit-mask to use for correct byte-alignment
+ virtual void *allocate(size_t num_bytes, size_t mask) = 0;
+
                         virtual void deallocate(void *base, size_t num_bytes) = 0;
                         virtual size_t max_size() const = 0;
                         virtual size_t remaining() const = 0;

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-13 04:10:08 EDT (Sat, 13 Jun 2009)
@@ -245,11 +245,49 @@
 
 void test_alignment()
 {
+ monotonic::inline_storage<10000> storage;
+ typedef boost::array<char, 3> c0;
+ typedef boost::array<char, 6> c1;
+ typedef boost::array<char, 11> c2;
+ typedef boost::array<char, 31> c3;
+ typedef boost::array<char, 33> c4;
+ typedef boost::array<char, 57> c5;
+ typedef boost::array<char, 111> c6;
+
+ monotonic::vector<c0> v0(storage);
+ monotonic::vector<c1> v1(storage);
+ monotonic::vector<c2> v2(storage);
+ monotonic::vector<c3> v3(storage);
+ monotonic::vector<c4> v4(storage);
+ monotonic::vector<c5> v5(storage);
+ monotonic::vector<c6> v6(storage);
+
+ v0.resize(5);
+ v1.resize(5);
+ v2.resize(5);
+ v3.resize(5);
+ v4.resize(5);
+ v5.resize(5);
+ v6.resize(5);
+#define write_cn(n) \
+ BOOST_FOREACH(c ## n &c, v ## n) \
+ c = c ## n();
+ write_cn(0);
+ write_cn(1);
+ write_cn(2);
+ write_cn(3);
+ write_cn(4);
+ write_cn(5);
+ write_cn(6);
+#undef write_cn
+
+
         test_loop_monotonic<char>();
         test_loop_monotonic<long>();
 
         test_loop_std<char>();
         test_loop_std<short>();
+
 }
 
 template <class List>
@@ -384,8 +422,8 @@
 
 int main()
 {
- test_auto_buffer();
         test_alignment();
+ test_auto_buffer();
         test_speed();
         test_speed_heap();
         test_map_list_realtime();


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