I have created a map of type <int, string>. It contains 5.7 million records.
I read these records from file. It takes about 40 seconds to read it. Then
i do the processing. In the end, I try to call map.clear. The program takes
to ages to implement this command and move forward.
I am using visual studio 2010.
I also tried to run a for loop from map.begin() to map.end(). and call erase.
I used following loop.
j=0;
map<string,int>::iterator it1;
for (it1=sitesmap.begin(); it1!=sitesmap.end(); ++it1) {
sitesmap[it1->first].erase();
j++; if (j % 100000 == 0) cout<<j<<endl;
}
Ordinarily I thought, this loop would run for 5.7 million times. But it runs
many millions more. I dont know what is happening. Could anyone tell me,
1) why it takes ages to clear the memory of this map
2) why this loop runs more than 5.7 million times.
> I try to call map.clear. The program takes to ages to implement this command and move forward.
> I am using visual studio 2010.
Are you executing this from within the debugger? (Using the checked iterators in conjunction with the debug heap can take a lot of time.) Or is it excruciatingly slow with the release build as well?