C++ 中 pop_front() 的分段错误
我的问题是,在调用“processList.pop_front()
”后出现分段错误。如果我注释掉“processList.pop_front()
”,则在 tt.pop_front()
调用之后、最外层 for 循环的第二次迭代期间会发生分段内部 for 循环已经进行了近 5000 次迭代。我看不出问题出在哪里。有什么想法吗?
loopLimit = processList.size();
for(int i = 0; i < loopLimit; i++)
{
tempProcess = processList.front();
tt = tempProcess.memAccesses;
cout << "process number " << i << "\n";
while(!tt.empty())
{
t = tt.front();
tt.pop_front();
cout << "from processlist: " << t.instrType << " " << t.instrAddr << "\n";
}
if(!processList.empty())
{
cout << "size is now: " << processList.size() << "\n";
processList.pop_front();
}
}
My problem is that I am getting a segmentation fault that occurs after I call "processList.pop_front()
". If I comment out "processList.pop_front()
", a segmentation then occurs during the second iteration of the outermost for loop, after a tt.pop_front()
call, after that inner for loop has gone through almost 5000 iterations. I can't see what the problem is. Any thoughts?
loopLimit = processList.size();
for(int i = 0; i < loopLimit; i++)
{
tempProcess = processList.front();
tt = tempProcess.memAccesses;
cout << "process number " << i << "\n";
while(!tt.empty())
{
t = tt.front();
tt.pop_front();
cout << "from processlist: " << t.instrType << " " << t.instrAddr << "\n";
}
if(!processList.empty())
{
cout << "size is now: " << processList.size() << "\n";
processList.pop_front();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个类似的问题,我通过向双端队列添加一个无效值来解决它:
可能你需要稍微调整一下。
这不是一个很好的解决方案,但它确实有效。
I have a similar problem and I solved it by adding an invalid value to the deque:
Probably you will have to adapt it a bit.
Is not a very nice solution, but it works.