Calling .clear () or .erase () in C ++ std :: multimap sometimes causes freezing (100% processor)

We use multimap to quickly find values ​​/ indices declared as

typedef double Numerical; std::multimap<Numerical, Int32> SortableRowIndex; 

And we fill it in pairs using

 SortableRowIndex.insert(std::pair<Numerical, Int32>(GetSortable(i), i)); 

The GetSortable () function always returns double. And it works great. Iterating through values ​​works fine. But then the weird part comes ... sometimes when we try to clear the data ...

 SortableRowIndex.clear(); 

... it goes into some kind of cycle and stalls / races, clogging the processor core used by 100%.

The explicit method seems to be inherited from xtree (the system file), and inside it there is only a bunch of lines:

  void clear() _NOEXCEPT { // erase all #if _ITERATOR_DEBUG_LEVEL == 2 this->_Orphan_ptr(*this, 0); #endif /* _ITERATOR_DEBUG_LEVEL == 2 */ _Erase(_Root()); _Root() = this->_Myhead; _Lmost() = this->_Myhead; _Rmost() = this->_Myhead; this->_Mysize = 0; } 

For some reason, my Visual Studio 2013 will not allow me to enter this method when debugging ... and I can not, because life finds out to me what the problem is!

Any help would be ridiculously appreciated!

+5
source share
1 answer

As it turned out, this doesn’t slow down much, but cleaning multimedia through the Visual Studio debugger is REALLY SLOW. I noticed that the memory is freed, and let it work for a couple of minutes, and then it was finally completed. Running the application outside of Visual Studio caused the .clear () calls to drop out to <1s, even for millions of pairs.

So, heads-up, if you clear huge multimaxes while working in debug mode in visual studio. This is sloooooow.

+3
source

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


All Articles