I wanna store small objects in unordered_map, just wondering if it may copy/release contained objects if there is any insert/remove/rehash operation? I think unordered_map uses link list to store key/value pair, it should not need to copy/release objects like vector for memory reallocation.
C++11 standard: § 23.2.5/8
The elements of an unordered associative container are organized into buckets. Keys with the same hash code appear in the same bucket. The number of buckets is automatically increased as elements are added to an unordered associative container, so that the average number of elements per bucket is kept below a bound. Rehashing invalidates iterators, changes ordering between elements, and changes which buckets elements appear in, but does not invalidate pointers or references to elements. For unordered_multiset and unordered_multimap, rehashing preserves the relative ordering of equivalent elements.
In short for unordered_map
,
In case of Insert/Erase operations,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With