diff --git a/libs/pbd/pbd/stack_allocator.h b/libs/pbd/pbd/stack_allocator.h index 742cf39b6d..9eed081ec0 100644 --- a/libs/pbd/pbd/stack_allocator.h +++ b/libs/pbd/pbd/stack_allocator.h @@ -19,6 +19,7 @@ #ifndef PBD_STACK_ALLOCATOR_H #define PBD_STACK_ALLOCATOR_H +#include #include #include "pbd/libpbd_visibility.h" @@ -60,22 +61,22 @@ public: }; StackAllocator () - : _ptr (_buf.data()) + : _ptr ((pointer)&_buf) { } StackAllocator (const StackAllocator&) - : StackAllocator () + : _ptr ((pointer)&_buf) { } template StackAllocator (const StackAllocator&) - : StackAllocator () + : _ptr ((pointer)&_buf) { } /* inspired by http://howardhinnant.github.io/stack_alloc.h */ pointer allocate (size_type n, void* hint = 0) { - if (_buf.data() + stack_capacity >= _ptr + n) { + if ((pointer)&_buf + stack_capacity >= _ptr + n) { DEBUG_STACK_ALLOC ("Allocate %ld item(s) of size %zu on the stack\n", n, sizeof (T)); pointer rv = _ptr; _ptr += n; @@ -107,12 +108,12 @@ public: bool operator== (StackAllocator const& a) const { - return _buf.data() == a._buf.data(); + return &_buf == &a._buf; } bool operator!= (StackAllocator const& a) const { - return _buf.data() != a._buf.data(); + return &_buf != &a._buf; } template @@ -146,10 +147,12 @@ private: bool pointer_in_buffer (pointer const p) { - return (_buf.data() <= p && p < _buf.data() + stack_capacity); + return ((pointer const)&_buf <= p && p < (pointer const)&_buf + stack_capacity); } - alignas(16) std::array _buf; + typedef typename boost::aligned_storage::type align_t; + + align_t _buf; pointer _ptr; };