|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53863 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-13 04:51:58
Author: cschladetsch
Date: 2009-06-13 04:51:56 EDT (Sat, 13 Jun 2009)
New Revision: 53863
URL: http://svn.boost.org/trac/boost/changeset/53863
Log:
improvement to performance of alignment
Text files modified:
sandbox/monotonic/boost/monotonic/allocator.h | 4 ++--
sandbox/monotonic/boost/monotonic/inline_storage.h | 21 ++++++++++++++++++---
sandbox/monotonic/boost/monotonic/storage_base.h | 4 ++--
sandbox/monotonic/libs/monotonic/test/main.cpp | 14 ++++++++++++++
4 files changed, 36 insertions(+), 7 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:51:56 EDT (Sat, 13 Jun 2009)
@@ -97,13 +97,13 @@
return &x;
}
- BOOST_STATIC_CONSTANT(size_t, alignment_mask = boost::aligned_storage<sizeof(T)>::alignment - 1);
+ BOOST_STATIC_CONSTANT(size_t, alignment = boost::aligned_storage<sizeof(T)>::alignment);
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), alignment_mask));
+ return static_cast<T *>(storage->allocate(num*sizeof(T), alignment));
}
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:51:56 EDT (Sat, 13 Jun 2009)
@@ -42,6 +42,18 @@
{
}
+ buffer_type const &get_buffer() const
+ {
+ return buffer;
+ }
+ const char *begin() const
+ {
+ return &buffer[0];
+ }
+ const char *end() const
+ {
+ return &buffer[N - 1];
+ }
void reset()
{
cursor = 0;
@@ -57,12 +69,15 @@
cursor = c;
}
- /// allocate storage, given alignment mask
- void *allocate(size_t num_bytes, size_t mask)
+ /// allocate storage, given alignment requirement
+ void *allocate(size_t num_bytes, size_t alignment)
{
// ensure we return a point on an aligned boundary
- size_t extra = num_bytes & mask;
+ size_t extra = cursor & (alignment - 1);
+ if (extra > 0)
+ extra = alignment - extra;
size_t required = num_bytes + extra;
+ BOOST_ASSERT(cursor + required <= N);
#ifdef BOOST_MONOTONIC_USE_AUTOBUFFER
buffer.uninitialized_resize(buffer.size() + required);
#endif
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:51:56 EDT (Sat, 13 Jun 2009)
@@ -12,8 +12,8 @@
/// base structure for inline_storage<N>
struct storage_base
{
- // 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;
+ // the number of bytes to allocate, and the alignment to use
+ virtual void *allocate(size_t num_bytes, size_t alignment) = 0;
virtual void deallocate(void *base, size_t num_bytes) = 0;
virtual size_t max_size() 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:51:56 EDT (Sat, 13 Jun 2009)
@@ -246,6 +246,20 @@
void test_alignment()
{
monotonic::inline_storage<10000> storage;
+
+ // the two arguments to storage.allocate are the size, and the required alignment
+ void *P = storage.allocate(3, 4);
+ assert(P == storage.begin() + 0);
+
+ P = storage.allocate(3, 4);
+ assert(P == storage.begin() + 4);
+
+ P = storage.allocate(11, 4);
+ assert(P == storage.begin() + 8);
+
+ P = storage.allocate(11, 16);
+ assert(P == storage.begin() + 32);
+
typedef boost::array<char, 3> c0;
typedef boost::array<char, 6> c1;
typedef boost::array<char, 11> c2;
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