Вопрос

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().

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top