使用 STXXL 队列时,“未分配正在释放的指针”

`pointer being freed was not allocated` when using stxxl queue

本文关键字:释放 指针 分配 队列 STXXL 使用      更新时间:2023-10-16

我的代码似乎有效(由于上述错误,我没有尝试过大型数据集)。

法典:

#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,0,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,所以现在您的intvalue_type。Line 的 00072 和 00073 表明您的正面和背面元素属于该value_type。您是否看到它们将如何维护为指针。最后,如果您查看任何构造函数,则在 00069 行上定义的pool_type* pool将是"new'd"的(这是元素的基础),并且始终调用 init 函数。在 init 中,调用pool->steal(),如果您想了解更多信息,请单击它。

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