Author: aconway
Date: Thu Jun  5 13:41:59 2008
New Revision: 663731

URL: http://svn.apache.org/viewvc?rev=663731&view=rev
Log:
Fixed bug in InlineAllocator

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/InlineAllocator.h

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/InlineAllocator.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/InlineAllocator.h?rev=663731&r1=663730&r2=663731&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/InlineAllocator.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/InlineAllocator.h Thu Jun  5 
13:41:59 2008
@@ -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 @@
     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 @@
     };
 
   private:
-    value_type store[Max];
+    boost::aligned_storage<
+      sizeof(value_type)*Max,
+      boost::alignment_of<value_type>::value
+      > store;
     bool allocated;
 };
 


Reply via email to