C++中的iterator->second

std::map<X, Y>实际储存了一串std::pair<const X, Y>

std::map<std::string, int> m = /* fill it */;
auto it = m.begin();

这里,如果你用*it,那么你将得到map第一个元素的std::pair

现在你可以接收std::pair的两个元素:

(*it).first会得到key

(*it).second会得到value

这等同于it->firstit->second

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
麻烦优化一下下列C++代码 void PIN_FAST_ANALYSIS_CALL onRead(THREADID threadid, ADDRINT memoryAddr){ ThreadData* t = get_tls(threadid); t->readCounter++; // get latest version value of this memory location map<ADDRINT, std::pair<vector<UINT32>, std::pair<THREADID, UINT32> > >::iterator it = t->shadowRead.find(memoryAddr); if (it != t->shadowRead.end()){ // if its in the thread's local memory /*(implementation of the last one value predictor)*/ // if it already exists. update the counter for the thread by 1 // for the location. it->second.first[threadid]++; } else { // if hasn't been read by current thread before //insert record into memoryMap vector <UINT32> temp(8,0); t->shadowRead[memoryAddr] = std::make_pair(temp, std::make_pair(0,0)); // insert pair of vector and another pair t->shadowRead[memoryAddr].first[threadid] = 1; } // Get last write to memoryAddr and save order with read in execution log PIN_GetLock(&writeLock, threadid + 1); rdOps++; unordered_map<ADDRINT, std::pair<vector<std::pair<THREADID, UINT32> > ,bool> >::iterator itt = memoryMap.find(memoryAddr); map<ADDRINT, std::pair<vector<UINT32>, std::pair<THREADID, UINT32> > >::iterator ita = t->shadowRead.find(memoryAddr); if ((itt != memoryMap.end()) && (itt->second.first.size() > 0) && (itt->second.first.back().first != t->tid) && (itt->second.first.back().first != ita->second.second.first && itt->second.first.back().second != ita->second.second.second)){ // optimize to weed out intra-thread dependencies on shared memory locations //EXECUTION LOG FORMAT WRITE-READ: WRITETHREAD WRITECOUNTER READ traceFileReads << itt->second.first.back().first << "," << itt->second.first.back().second << "," << t->tid << "," << t->readCounter << endl; } PIN_ReleaseLock(&writeLock);
07-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值