Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
2403 Discussions

set initial capacity of concurrent_hash_map

zuviria__eduardo
Beginner
253 Views

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
Pavel_K_Intel1
Employee
253 Views

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