From 702fc1b569f5991dcc65ea1428586db9d40f8f95 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 5 Jun 2008 20:41:59 +0000 Subject: Fixed bug in InlineAllocator git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@663731 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/InlineAllocator.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'cpp/src') 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 +#include +#include #include 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(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 @@ -64,7 +68,10 @@ class InlineAllocator : public BaseAllocator { }; private: - value_type store[Max]; + boost::aligned_storage< + sizeof(value_type)*Max, + boost::alignment_of::value + > store; bool allocated; }; -- cgit v1.2.1