From d3c9e9725c8fa014e9ecdd421e967bd53d962b08 Mon Sep 17 00:00:00 2001 From: "Charles E. Rolke" Date: Fri, 14 Oct 2011 14:57:58 +0000 Subject: QPID-3540 Typecasting and alignment requirements for various platforms In RefCountedBuffer: 1. Pad the instantiantion address of RefCountedBuffer class up to an 8-byte boundary. 2. Add (void *) casts to 'store' pointer to prevent warnings about alignment. In qpid-perftest: 1. Don't pull a size_t object from an arbitrary buffer address. Instead, memcopy the object by bytes. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1183378 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/RefCountedBuffer.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'cpp/src/qpid/RefCountedBuffer.cpp') diff --git a/cpp/src/qpid/RefCountedBuffer.cpp b/cpp/src/qpid/RefCountedBuffer.cpp index 40d620f7ad..7e15eefeea 100644 --- a/cpp/src/qpid/RefCountedBuffer.cpp +++ b/cpp/src/qpid/RefCountedBuffer.cpp @@ -26,15 +26,26 @@ namespace qpid { void RefCountedBuffer::released() const { this->~RefCountedBuffer(); - ::delete[] reinterpret_cast(this); + uintptr_t binStoreRaw = reinterpret_cast(this); + binStoreRaw -= alignPad; + ::delete[] reinterpret_cast(binStoreRaw); } BufferRef RefCountedBuffer::create(size_t n) { - char* store=::new char[n+sizeof(RefCountedBuffer)]; + char * storeRaw = ::new char[n + sizeof(RefCountedBuffer) + + refCountedBufferStructAlign]; + uintptr_t binStoreRaw = reinterpret_cast(storeRaw); + uintptr_t binStore = (binStoreRaw + + refCountedBufferStructAlign-1) & ~(refCountedBufferStructAlign-1); + char * store = reinterpret_cast(binStore); + new(store) RefCountedBuffer; + + reinterpret_cast((void *)store)->alignPad = binStore - binStoreRaw; + char* start = store+sizeof(RefCountedBuffer); return BufferRef( - boost::intrusive_ptr(reinterpret_cast(store)), + boost::intrusive_ptr(reinterpret_cast((void *)store)), start, start+n); } -- cgit v1.2.1