Frage

The maximum size of my collection (an unordered_map) is known beforehand, so I want to reserve memory at start up for optimization. Does the member function reserve() achieve that purpose? The documentation says it will reserve the right number of buckets to contain N elements. Does that mean it will reserve space for N elements and reuse those as long as I don't have more than N elements in the map? The purpose is for LRU caching so an element has to be evicted, before a new one is added. I just want to make sure that memory is reused when an erase_element() is followed by insert_newelement().

War es hilfreich?

Lösung

Yes. The std:unordered_map has the member function reserve() exactly for that purpose.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top