pool: avoid alignment warnings on ARM

This commit is contained in:
Danny Robson 2017-01-05 19:50:00 +11:00
parent 98dc992473
commit ee53f8234b
2 changed files with 25 additions and 25 deletions

View File

@ -28,39 +28,39 @@ namespace util {
/// item destructors at pool destruction time. /// item destructors at pool destruction time.
template <typename T> template <typename T>
class pool : public nocopy { class pool : public nocopy {
protected: protected:
union node { union alignas (T) node {
node *_node; node *_node;
char _data[sizeof (T)]; char _data[sizeof (T)];
}; };
node *m_head; // root address of allocation node *m_head; // root address of allocation
node *m_next; // next available entry in the linked list node *m_next; // next available entry in the linked list
const size_t m_capacity; const size_t m_capacity;
size_t m_size; size_t m_size;
public: public:
explicit explicit
pool (unsigned int _capacity); pool (unsigned int _capacity);
~pool (); ~pool ();
// Data management // Data management
template <typename ...Args> template <typename ...Args>
T* acquire (Args&... args); T* acquire (Args&... args);
void release (T *data); void release (T *data);
size_t capacity (void) const; size_t capacity (void) const;
size_t size (void) const; size_t size (void) const;
bool empty (void) const; bool empty (void) const;
// Indexing // Indexing
size_t index (const T*) const; size_t index (const T*) const;
T& operator[] (size_t idx) &; T& operator[] (size_t idx) &;
const T& operator[] (size_t idx) const&; const T& operator[] (size_t idx) const&;
}; };
} }

View File

@ -98,7 +98,7 @@ namespace util {
// save what will become the next node shortly. it could be overwritten // save what will become the next node shortly. it could be overwritten
// in the constructor we're about to call. // in the constructor we're about to call.
node *newnext = m_next->_node; node *newnext = m_next->_node;
T *data = reinterpret_cast<T*> (m_next->_data); T *data = reinterpret_cast<T*> (m_next);
// try to construct the returnable object. // try to construct the returnable object.
try { try {