使用 STXXL 队列时,“未分配正在释放的指针”
`pointer being freed was not allocated` when using stxxl queue
我的代码似乎有效(由于上述错误,我没有尝试过大型数据集)。
法典:
#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
,所以现在您的int
是value_type
。Line 的 00072 和 00073 表明您的正面和背面元素属于该value_type
。您是否看到它们将如何维护为指针。最后,如果您查看任何构造函数,则在 00069 行上定义的pool_type* pool
将是"new'd"的(这是元素的基础),并且始终调用 init
函数。在 init
中,调用pool->steal()
,如果您想了解更多信息,请单击它。
简而言之,您需要将新的整数推送到队列中。界面不好,不是你的错。
相关文章:
- 正在理解智能指针,但出现错误:未分配正在释放的指针
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- 如何在向量中释放指针?
- 在C++中释放内存期间,迭代器与指针有何不同
- 包含矢量指针的结构的内存释放问题
- 错误:malloc:对象 0x7f9edf504080 的 *** 错误:未分配正在释放的指针
- 错误:释放指针未分配在矢量模板类C 中
- 如何在指针初始化为数组的第一个索引后释放指针
- 如何释放指针树中的所有内存
- 从 std::align 中释放指针
- C :释放指针没有分配在课堂上
- 构造向量 C++ 后无法释放指针
- nullptr是否释放指针的内存
- C/C++ 通过调用引用或直接释放指针
- 分段释放指针向量的错误
- 有效地从指向对象本身释放指针
- 如何释放指针向量中的元素
- Sqlite c/c++api,负责从sqlite3_column_text中释放指针
- 释放指针后分配给指针
- 正在释放指针