summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-06-05 20:41:59 +0000
committerAlan Conway <aconway@apache.org>2008-06-05 20:41:59 +0000
commit7bef4467ebb684bad5cc66976152caa4d02453ff (patch)
tree6a85dd629e9cc7eee84542ec4ec173e56351107b /qpid/cpp
parentbd82edd601db8e788ebbdcbfa9c0b0aa3cedcc8f (diff)
downloadqpid-python-7bef4467ebb684bad5cc66976152caa4d02453ff.tar.gz
Fixed bug in InlineAllocator
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@663731 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/src/qpid/InlineAllocator.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/qpid/cpp/src/qpid/InlineAllocator.h b/qpid/cpp/src/qpid/InlineAllocator.h
index fd652aca03..80cf9d90a7 100644
--- a/qpid/cpp/src/qpid/InlineAllocator.h
+++ b/qpid/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;
};