Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
43 Views

set initial capacity of concurrent_hash_map

Does anybody knows of a concrete example for setting the initial capacity on the concurrrent_hash_map? I found recommendations of doing this to improve performance  but looking at the members of the class it seems that you need to define a memory allocator too.

Thanks

0 Kudos
1 Reply
Highlighted
Employee
43 Views

Hi, really specifying initial

Hello, really specifying initial capacity can be useful for performance. If you know that after creating concurrent_hash_map instert or emplace operations will be performed, allocating at the beginning of the memory will save time on inserts in concurrent_hash_map.

If you do not specify the allocator as a template parameter, then the default allocator will be taken, in the file concurrent_hash_map.h you can find a list of default template parameters .

So an example of such a constructor might be:

concurrent_hash_map<int, int> my_map(10);
0 Kudos