문제

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