相关疑难解决方法(0)

++ iterator和iterator ++之间的性能差异?

我的同事声称对于对象类型,preincrement比post增量更有效

例如

std::vector<std::string> vec;

... insert a whole bunch of strings into vec ...

// iterate over and do stuff with vec.  Is this more efficient than the next 
// loop?
std::vector<std::string>::iterator it;
for (it = vec.begin(); it != vec.end(); ++it){

}

// iterate over and do stuff with vec.  Is this less efficient than the previous loop?
std::vector<std::string>::iterator it;
for (it = vec.begin(); it != vec.end(); it++){

}
Run Code Online (Sandbox Code Playgroud)

c++ performance

26
推荐指数
3
解决办法
1万
查看次数

迭代C++映射给出无限循环

我有以下方法C++,只tableId从地图中删除与特定关联的元素.

 69 void
 70 ObjectFinder::flush(uint64_t tableId) {
 71 
 72     RAMCLOUD_TEST_LOG("flushing object map");
 74     // find everything between tableId, 0
 75     // keep scanning util find all the entries for that table
 76     std::map<TabletKey, ProtoBuf::Tablets::Tablet>::const_iterator it;
 79     for (it = tableMap.begin(); it != tableMap.end(); it++) {
 80         TabletKey current = it->first;
 81         if (tableId == current.first) {
 82             tableMap.erase(current);
 83         }
 84     }
 85     std::cout << "hello" << std::endl;
 87 }
Run Code Online (Sandbox Code Playgroud)

进入代码时gdb我发现在循环迭代后发生了无限for循环.该行85 …

c++ map infinite-loop

0
推荐指数
1
解决办法
2541
查看次数

标签 统计

c++ ×2

infinite-loop ×1

map ×1

performance ×1