Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Yumo_J_
Beginner
65 Views

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

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
65 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
 

Reply