My code seems to work(I haven't tried it with large datasets because of the above error).
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
is simply: disk=./testfile,0,syscall
But my error 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 troubleshoot it, do I need to free 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).
I've never used stxxl before but since it's a template you can take a look at the code here: http://algo2.iti.kit.edu/stxxl/trunk/queue_8h_source.html. And since you're a newbie I'll explain a few things. This goofy queue maintains a queue of pointers. Line 00054 shows typedef ValTp value_type
, so now your int
is a value_type
. Line's 00072 & 00073 show that your front and back elements are of that value_type
. Do you see how they will be maintained as pointers. Finally if you look at any constructor the 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 within init
, pool->steal()
is called, click on it if you want to learn more.
In short, you need to be pushing new'd up integers onto your queue. Bad interface, not your fault.