[Boost.Multi-index] empty container allocates 1 unused node
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? If not, what is this memory used for? Is there any way to avoid this allocation? Regards, Jakub
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
participants (2)
-
Jakub Jablonski
-
joaquin@tid.es