From ee53f8234b0cd575ffa3bd390273c9d6e0807671 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 5 Jan 2017 19:50:00 +1100 Subject: [PATCH] pool: avoid alignment warnings on ARM --- pool.hpp | 48 ++++++++++++++++++++++++------------------------ pool.ipp | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pool.hpp b/pool.hpp index cd601c7e..d3ea16ef 100644 --- a/pool.hpp +++ b/pool.hpp @@ -28,39 +28,39 @@ namespace util { /// item destructors at pool destruction time. template class pool : public nocopy { - protected: - union node { - node *_node; - char _data[sizeof (T)]; - }; + protected: + union alignas (T) node { + node *_node; + char _data[sizeof (T)]; + }; - node *m_head; // root address of allocation - node *m_next; // next available entry in the linked list + node *m_head; // root address of allocation + node *m_next; // next available entry in the linked list - const size_t m_capacity; - size_t m_size; + const size_t m_capacity; + size_t m_size; - public: - explicit - pool (unsigned int _capacity); + public: + explicit + pool (unsigned int _capacity); - ~pool (); + ~pool (); - // Data management - template - T* acquire (Args&... args); + // Data management + template + T* acquire (Args&... args); - void release (T *data); + void release (T *data); - size_t capacity (void) const; - size_t size (void) const; - bool empty (void) const; + size_t capacity (void) const; + size_t size (void) const; + bool empty (void) const; - // Indexing - size_t index (const T*) const; + // Indexing + size_t index (const T*) const; - T& operator[] (size_t idx) &; - const T& operator[] (size_t idx) const&; + T& operator[] (size_t idx) &; + const T& operator[] (size_t idx) const&; }; } diff --git a/pool.ipp b/pool.ipp index e830f32b..ea02ac98 100644 --- a/pool.ipp +++ b/pool.ipp @@ -98,7 +98,7 @@ namespace util { // save what will become the next node shortly. it could be overwritten // in the constructor we're about to call. node *newnext = m_next->_node; - T *data = reinterpret_cast (m_next->_data); + T *data = reinterpret_cast (m_next); // try to construct the returnable object. try {