Boost Users :
Subject: Re: [Boost-users] multi_index reserve but allocate
From: Olivier Tristan (o.tristan_at_[hidden])
Date: 2019-03-20 08:15:03
My goal is not to be fast but to avoid allocation as I am in a high
priority thread and I want to avoid possible allocation lock.
I tried the allocator solution following a thread on stackoverflow
(where you answered as well)
using something like that
boost::details::pool::default_mutex, 256U, 0U>>;
My issue with this solution is that the pool is actually shared across
all object using a boost::pool_allocator that requires a mutex as there
are multiple thread in my app.
One solution could be to tag the allocator but this seems to be not
possible anymore unless I am mistaken
Is there a way otherwise to get a pool for each instances of my
Le 19/03/2019 Ã 21:49, Joaquin M LÃ³pez MuÃ±oz via Boost-users a Ã©critÂ :
> El 19/03/2019 a las 18:14, Olivier Tristan via Boost-users escribiÃ³:
> Hi Olivier,
>> Looks like that even if I call reserve on a multi_index, it stills
>> allocate memory while I am still below
>> the reserve size.
>> Is this the intended behavior ?
> Yes it is. multi_index_container is node based, and, like std
> node-based containers (std::list, std::set,
> std::unordered_set, etc.), will allocate memory for its nodes as needed.
> Hashed and random-access indices provide reserve() member functions
> (with non-equivalent
> semantics) that control the size of internal contiguous memory chunks
> maintained by these indices
> additionally to the nodes. So, reserve() (when available) does not
> (nor is designed to) guarantee
> that no additional memory will be allocated on further insertions.
>> If so, what is the best way to avoid allocation in a fixed sized
> You can write your own allocator that allocates the memory beforehand
> and then serves it
> piece by piece on allocate(). I suspect, however, that this is not
> going to be faster than using
> the default std::allocator.
>> Thanks !
> JoaquÃn M LÃ³pez MuÃ±oz
> Boost-users mailing list
-- Olivier Tristan Research & Development www.uvi.net
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net