I came across the strange behavior of std :: set.
Here is the code:
#include <cstdio> #include <windows.h> #include <stdlib.h> #include <vector> #include <set> using namespace std; int main(int argc, char *argv[]) { set<int> b[100]; for (int o=0; o<10; o++) { int tt = GetTickCount(); for (int i=0; i<5000000; i++) { b[o].insert(i); } tt = GetTickCount() - tt; b[o].clear(); printf("%d\n", tt); } return 0; }
I am running on Windows XP.
Here's the interesting part: this first print time is about 3,500 ms, and all the rest is over 9,000 ms! Why is this happening?
Oh, and this only happens in the release version (-O2 optimization).
This does not happen on Linux (after changing the code to compile there).
One more thing: when I run it when profiling using Intel VTune, it always takes about 3000 ms, which is why it should be so.
UPDATE: Here is some new code:
#include <cstdio>
This is the same problem. What happens, I select a lot of small objects and then delete them randomly - so it looks like it looks in std :: set. Therefore, this is a Windows memory management issue. He can not cope with a large number of small allotments and deletions.
c ++ set windows stl
tweety3d
source share