3 ms·
That reserve() method only reserves memory for the hash table inside the container. It does help with performance to an extent, but the memory for the items sto
by Const-me 3y ago
That reserve() method only reserves memory for the hash table inside the container. It does help with performance to an extent, but the memory for the items stored in that map is still allocated one by one, as new entries are inserted into the map.
I think the main reason why reserve() helped substantially weren’t saved malloc() calls, it were saved re-hashes. Each time the hash table grows, it needs to re-insert all items currently stored on the map into the new, larger table of these buckets.