Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Multi-index] empty container allocates 1 unused node
From: joaquin_at_[hidden]
Date: 2010-03-04 09:55:57


Jakub Jablonski escribió:
> Hi,
> I was trying out some examples of using multi_index_container
> with custom allocator. I found out that even an empty container,
> on creation, allocates memory for a single node (but no element
> is stored inside). In other words, if I store N elements, the
> container allocates memory for N+1 elements.
>
> Is it a fault?
>

No, your appreciaton is correct, an empty multi_index_container
allocates one node.

> If not, what is this memory used for?
>

This node is known as a header node and simplifies the handling of the
internal data
structures such as rb-trees. For instance, end iterators point to this
header node.

> Is there any way to avoid this allocation?
>

Not from the user's side, I'm afraid.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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