pool: avoid alignment warnings on ARM
This commit is contained in:
parent
98dc992473
commit
ee53f8234b
48
pool.hpp
48
pool.hpp
@ -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&;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
pool.ipp
2
pool.ipp
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user