I have an unordered_map
storing large objects:
std::unordered_map<uint64_t, LargeObject> map;
LargeObject
is an array of POD/there are no pointer members.
I am receiving a lot of LargeObject
s, so I only want to insert them in the map if they don't already exist (there will be a lot of times they do already exist, as I am listening to multiple sources).
Performance matters, as I am receiving millions.
There seem to be several ways of doing this:
map[key] = largeObject;
or:
map.insert(std::make_pair<uint64_t, LargeObject>(key, largeObject);
or:
if(map.count(key) == 0)
{
map[key] = largeObject;
}
or:
auto iter = map.find(key);
if(iter == map.end())
{
map[key] = largeObject;
}
There maybe more I haven't included.
Which is the most efficient technique to insert when the map's value is a large object?