I have a situation where map elements will be inserted all throughout a continuous loop. I know that there's no reserve function for maps like there are for vectors, but I know exactly the maximum amount of elements there will be in the map, I just don't know the value of each individual map.
Would it be possible if I just inserted the maximum amount of elements in the beginning of the program, and change the value of each/any individual element later on? For example:
1 2 3 4 5 6 7 8
std::map<int, std::string> map;
//There will be a maximum of 200 elements in this map
for (int i = 0; i < 200; i++)
{
map[i];
}
//Change the value of individual elements as I wish
Is doing so a good idea? Is it more efficient than initializing on declaration if initializing will be done often?