Le 20/03/2019 à 11:18, Joaquin M López Muñoz via Boost-users a écrit :
Maybe you can give this allocator a try:
https://probablydance.com/2014/11/09/plalloc-a-simple-stateful-allocator-for...
It works with Boost.MultiIndex and does not use any mutex at all (because it's stateful and as such instances are owned by the containers using them).
I tried using directly boost::pool but I was struggling having an
allocator that actually compiled (last issue was related to swap)
This is a great example to start from.
In the meantime, I've found as well info regarding
boost::container::node_allocator but the memory is shared across
instances and do not allow preallocation.
Didn't found any other out of the box solution in boost though
so I've ended up modifying the example.
Still I need to do a reserve on multi_index to force the creation of all
the allocator
Thanks a lot !
For those interested, here is what I end up with
template <typename T>
struct PoolAlloc
{
typedef T value_type;
PoolAlloc(size_t reserveSize)
: reservedSize(reserveSize)
{
reserve(reserveSize);
}
template <typename U>
PoolAlloc(const PoolAlloc<U>& other)
: reservedSize(other.reservedSize)
{
reserve(reservedSize);
}
PoolAlloc(const PoolAlloc&) = delete;
PoolAlloc& operator=(const PoolAlloc&) = delete;
PoolAlloc(PoolAlloc&&) = default;
PoolAlloc& operator=(PoolAlloc&&) = default;
typedef std::true_type propagate_on_container_copy_assignment;
typedef std::true_type propagate_on_container_move_assignment;
typedef std::true_type propagate_on_container_swap;
void reserve(size_t to_allocate)
{
available.reserve(to_allocate);
std::unique_ptr