Why is the destructor in std::queue extremely slow? look at my example:
void test()
{
int total = 17173512;
std::queue<int> q;
for(int i = 0; i < total; i++)
q.push(i); //Push is very fast.
std::cout<<"Done"<<std::endl; //Less than a second.
}
test();
std::cout<<"Done"<<std::endl; //This takes several minutes!!
The destructor in std::vector is very fast...
UPDATED: My compiler/IDE is Visual studio 2012 Visual C++.
int main(int argc, char **argv)
{
int total = 17173512;
std::queue<int> q;
for(int i = 0; i < total; i++)
q.push(i);
std::cout<<"Done0"<<std::endl; //This takes less than a second.
while(!q.empty())
q.pop();
//This takes less than a second. Memory should be deallocated here!
std::cout<<"Done1"<<std::endl;
//Waiting forever, i.e. deallocating(HERE??) memory EXTREMELY SLOWLY.
//I can see how the memory is being deallocated here in windows task manager!
return 0;
}
With vector:
int main(int argc, char **argv)
{
int total = 17173512;
std::vector<int> q(total);
for(int i = 0; i < total; i++)
q[i] = 2000;
std::cout<<"Done"<<std::endl;
return 0; //Extremely fast.
}
UPDATE 2:
Everything is solved now! I uninstalled Visual studio 2012 + visual c++. I have installed Visual Studio Community 2015 and everything is much faster and works as expected!