mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 16:34:13 +01:00
ircd::allocate: Use std::aligned_storage for fixed allocator space.
This commit is contained in:
parent
d7b3a56882
commit
7f7278187f
1 changed files with 8 additions and 6 deletions
|
@ -80,9 +80,10 @@ struct ircd::allocator::fixed
|
||||||
:state
|
:state
|
||||||
{
|
{
|
||||||
struct allocator;
|
struct allocator;
|
||||||
|
using value = std::aligned_storage<sizeof(T), alignof(T)>;
|
||||||
|
|
||||||
std::array<word_t, max / 8> avail {{0}};
|
std::array<word_t, max / 8> avail {{0}};
|
||||||
std::array<T, max> buf alignas(16);
|
std::array<typename value::type, max> buf;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
allocator operator()();
|
allocator operator()();
|
||||||
|
@ -127,14 +128,15 @@ struct ircd::allocator::fixed<T, size>::allocator
|
||||||
|
|
||||||
pointer allocate(const size_type &n, const const_pointer &hint = nullptr)
|
pointer allocate(const size_type &n, const const_pointer &hint = nullptr)
|
||||||
{
|
{
|
||||||
const uint hintpos(hint? hint - s->buf.data() : -1);
|
const auto base(reinterpret_cast<pointer>(s->buf.data()));
|
||||||
return s->buf.data() + s->state::allocate(n, hintpos);
|
const uint hintpos(hint? hint - base : -1);
|
||||||
|
return base + s->state::allocate(n, hintpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate(const pointer &p, const size_type &n)
|
void deallocate(const pointer &p, const size_type &n)
|
||||||
{
|
{
|
||||||
const uint pos(p - s->buf.data());
|
const auto base(reinterpret_cast<pointer>(s->buf.data()));
|
||||||
s->state::deallocate(pos, n);
|
s->state::deallocate(p - base, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class U, size_t S>
|
template<class U, size_t S>
|
||||||
|
|
Loading…
Reference in a new issue