set initial capacity of concurrent_hash_map

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.


2 posts / 0 new

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);

Leave a Comment

Please sign in to add a comment. Not a member? Join today