Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2466 Discussions

Should key be preserved after concurrent hash map insert() ?

Yumo_J_
Beginner
253 Views

A quick question:

When using tbb concurrent hash map, does memory used by key during insert() requires to be preserved? I guess so because tbb may require it for equal() but like to get definite answer. For example, 

void add(const char *string, uint32_t type, void *data)  {

               MyKey key;

               key.string = string;
               key.type = type;
               map->insert(key, data);

   }

Sinc key is local, it will be destroyed once function returns. Is this okay or does TBB requires that the key instance to be preserved for the lifetime of object in the map

Thanks!

0 Kudos
1 Reply
Alexei_K_Intel
Employee
253 Views

Hi Yumo,

In accordance with documentation, value_type contains the Key type by value:

typedef std::pair<const Key,T> value_type;

I.e. the Key values are copied inside the container and should not be preserved after insertion.

Regards,
Alex
 

0 Kudos
Reply