加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 使用stxxl队列时,“被释放的指针未被分配”

发布时间:2020-12-16 06:59:54 所属栏目:百科 来源:网络整理
导读:我的代码似乎工作(由于上述错误,我没有尝试过大型数据集). 码: #include iostream#include queue#include stxxl/queueint main(){ //queueint q; //this works stxxl::queueint q; //does not work for (int i = 0; i100; i++) { q.push(i); } std::cout "d
我的代码似乎工作(由于上述错误,我没有尝试过大型数据集).

码:

#include <iostream>
#include <queue>
#include <stxxl/queue>

int main()
{
   //queue<int> q; //this works
   stxxl::queue<int> q; //does not work
   for (int i = 0; i<100; i++) {
       q.push(i);
   }
   std::cout << "done copying" << std::endl;
   while (q.empty() == false) {
       std::cout << q.front() << std::endl;
       q.pop();
   }
   std::cout << "done poping" << std::endl;
   return 0;
}

我的简单.stxxl就是:disk =./ testfile,syscall

但我的错误是:

stackexchangeexample(3884) malloc: *** error for object 0x101c04000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
The program has unexpectedly finished.

我不确定如何排除故障,在这种情况下我需要释放内存吗?我还在学习c很抱歉,如果这是非常基本的(这只有在我使用stxxl队列时才会发生).

解决方法

我之前从未使用过stxxl,但由于它是一个模板,你可以看看这里的代码: http://algo2.iti.kit.edu/stxxl/trunk/queue_8h_source.html.既然你是一个新手,我会解释一些事情.这个愚蠢的队列维护着一个指针队列.第00054行显示了typedef ValTp value_type,所以现在你的int是value_type. Line的00072& 00073显示您的前后元素属于该value_type.你看到它们将如何被维护为指针.最后,如果你看一下任何构造函数,在00069行定义的pool_type *池将是“new’d”up(这是你的元素的基础),并且始终调用init函数.在init中,调用pool-> steal(),如果你想了解更多,请点击它.

简而言之,您需要将新的整数推送到队列中.界面不好,不是你的错.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读