The `pointer that was freed was not assigned` when using the stxxl queue

My code seems to work (I have not tried it with large datasets due to the above error).

the code:

#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; } 

my simple .stxxl simple: disk=./testfile,0,syscall

But my mistake is:

 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. 

I'm not sure how to fix it, do I need to free up memory in this case? I'm still learning C ++, so sorry if this is really basic (this only happens when I use the stxxl queue).

+4
source share
1 answer

I have never used stxxl before, but since this is a template, you can see the code here: http://algo2.iti.kit.edu/stxxl/trunk/queue_8h_source.html . And since you're new, I’ll explain a few things. This stub queue supports a pointer queue. Line 00054 shows typedef ValTp value_type , so now your int is value_type . Lines 00072 and 00073 indicate that your front and back elements have a value_type value. You see how they will be supported as pointers. Finally, if you look at any constructor, then pool_type* pool , defined on line 00069, will be "new'd" up (which is the basis of your elements), and the init function is always called. And in init , pool->steal() is called, click on it if you want to know more.

In short, you need to push the new'd integers into your queue. Bad interface, not your mistake.

+1
source

Source: https://habr.com/ru/post/1412286/


All Articles