Why slow withdrawal?

I have a question for which I can not find the answer on the net ...

I have a set declared as follows:

set<unsigned int> MySet 

I enter a million random numbers generated from mersenne twister. Random generation and insertion are really fast (about a second for a million numbers), but the release is very slow (1 and a half minutes).

Why is the release so slow? I do not use any custom destructors to set.

+6
source share
2 answers

Compile your code in release mode.

It does two things.

  • Includes optimization that definitely helps.
  • Also, memory management libraries are different for debugging and release.
    The debug version of the library is built to provide debugging and contains additional information (for example, allocation of allocated memory). All this extra processing is really worth it.
    • The goal of the two versions of the library is completely different. The release version is definitely optimized to speed up the debug version, optimized for recovery and debugging.

Please note that this information is about DevStudio.

+7
source

Perhaps because it makes sense to optimize distribution through release, because many applications allocate without release, but never the other way around. I myself saw a similar model in an application that mixes calls with malloc and free (as opposed to distributing and releasing all at once).

I never wrote a heap allocator, so I don't know if there is a deeper technical reason. When exempting from unauthorized access, it is necessary to find and combine adjacent free blocks. Thus, the work is simply fundamentally different.

90 seconds for 1 million small free() sounds are pretty slow. I never programmed Windows, so I can’t say that it’s not normal, but the system should be able to do much better.

The solution to your problem may simply be to skip the release of objects before the program exits. You can try to get a custom allocator from std::allocator< unsigned int > , which makes deallocate no-op.

+1
source

Source: https://habr.com/ru/post/902360/


All Articles