|
Boost Users : |
Subject: Re: [Boost-users] multi_index reserve but allocate
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2019-03-19 20:49:01
El 19/03/2019 a las 18:14, Olivier Tristan via Boost-users escribió:
> Hi,
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
> multi_index
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 !
Best,
JoaquÃn M López Muñoz
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