0

Does boost::multi_index create a copy of the key object. This question came into my mind since std::map HAS to store a key object according to it's design. However boost::multi_index does not explicitly asks for the key but instead it is gathered from the stored object.

Another question is if boost::multi_index does create a copy of it's keys, is there any container which does not create a copy of it's keys to keep the footprint to the minimum?

Saif Ur Rehman
  • 338
  • 3
  • 14

1 Answers1

1

Boost.MultiIndex does not keep keys separately from the objects they're associated to, but relies on so-called key extractors to retrieve the info from the objects themselves, without external key storage.

Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20
  • So in respect to memory overhead of storing pointers to objects, which one(map or multi_index) uses less memory? – Saif Ur Rehman May 29 '14 at 07:55
  • 1
    The memory overhead of using pointers to objects rather than internally copying the objects is independent of what container you use. The aspect where Boost.MultiIndex can get you some memory savings relates to the fact that keys are implicitly part of the objects stored. – Joaquín M López Muñoz May 29 '14 at 10:10
  • Thanks that's exactly what I was asking for – Saif Ur Rehman May 29 '14 at 13:59