小编Lin*_*ult的帖子

在c ++ std :: multimap上调用.clear()或.erase()有时会导致冻结(100%cpu)

我们使用multimap进行快速值/索引查找,如下所示

typedef double Numerical;
std::multimap<Numerical, Int32> SortableRowIndex;
Run Code Online (Sandbox Code Playgroud)

我们用对子填充它们

SortableRowIndex.insert(std::pair<Numerical, Int32>(GetSortable(i), i));
Run Code Online (Sandbox Code Playgroud)

函数GetSortable()总是返回一个double.这很好用.迭代这些值也可以正常工作.但接下来是奇怪的部分...有时我们试图清除数据......

SortableRowIndex.clear();
Run Code Online (Sandbox Code Playgroud)

...它会进入某种循环和失速/比赛,以100%的速度占用CPU的核心.

clear方法似乎是从xtree(系统文件)继承而来的,其中只有一行内联:

    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;
        }
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我的Visual Studio 2013在调试时不会让我进入这个方法......我不能,因为我的生活中弄清楚问题是什么!

任何帮助都将受到极大的赞赏!

c++ multimap erase clear

5
推荐指数
1
解决办法
442
查看次数

标签 统计

c++ ×1

clear ×1

erase ×1

multimap ×1