vendredi 8 septembre 2017

How to optimize heavy map insertion in C++ regarding CPU and memory

I am iterating a map where I need to add elements on that map depending on a condition that an element is not found (it could be any other condition).

My main problem is that with a big scale of updates to be added, the application takes the whole CPU and all the memory.

Do you have any suggestions on how to improve this?

std::map<int, State> data;

const std::map<int, State>& update;

for (auto const& updatePos : update) {
    if (updateElemNotFound) { 
        data.insert(std::make_pair(updatePos.first, updatePos.second));
    }
}

Aucun commentaire:

Enregistrer un commentaire