diff options
author | Alan Conway <aconway@apache.org> | 2008-06-05 20:41:59 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-06-05 20:41:59 +0000 |
commit | 702fc1b569f5991dcc65ea1428586db9d40f8f95 (patch) | |
tree | 95d422b739c63d034a2c2e7e30a8a047d23a7fc8 /cpp/src | |
parent | fcb006c8ee035e6009d8cd986762dbae7b8eeffa (diff) | |
download | qpid-python-702fc1b569f5991dcc65ea1428586db9d40f8f95.tar.gz |
Fixed bug in InlineAllocator
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@663731 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/InlineAllocator.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/cpp/src/qpid/InlineAllocator.h b/cpp/src/qpid/InlineAllocator.h index fd652aca03..80cf9d90a7 100644 --- a/cpp/src/qpid/InlineAllocator.h +++ b/cpp/src/qpid/InlineAllocator.h @@ -23,6 +23,8 @@ */ #include <memory> +#include <boost/type_traits/aligned_storage.hpp> +#include <boost/type_traits/alignment_of.hpp> #include <assert.h> namespace qpid { @@ -39,22 +41,24 @@ class InlineAllocator : public BaseAllocator { typedef typename BaseAllocator::value_type value_type; InlineAllocator() : allocated(false) {} + InlineAllocator(const InlineAllocator& x) : BaseAllocator(x), allocated(false) {} pointer allocate(size_type n) { if (n <= Max && !allocated) { allocated=true; - return store; + return reinterpret_cast<value_type*>(store.address()); } else return BaseAllocator::allocate(n, 0); } void deallocate(pointer p, size_type n) { - if (p == store) { + if (p == store.address()) { assert(allocated); allocated=false; } - else BaseAllocator::deallocate(p, n); + else + BaseAllocator::deallocate(p, n); } template<typename T1> @@ -64,7 +68,10 @@ class InlineAllocator : public BaseAllocator { }; private: - value_type store[Max]; + boost::aligned_storage< + sizeof(value_type)*Max, + boost::alignment_of<value_type>::value + > store; bool allocated; }; |