I have a simple question. I have a few files, one file is around ~20000 lines.
It has 5 fields, have some other adt (vectors and lists), but those do not cause a segfault.
The map itself will store a key value, equivalent to about 1 per line.
When I added a map to my code, I would instantly get a segfault, I copied 5000 of 20000 lines, and receive a segfault, then 1000, and it worked.
In java there is a way to increase the amount of virtually allocated memory, is there a way to do so in c++? I have even deleted elements as they are no longer used, and I can get around 2000 lines, but not more.
Here is gdb:
(gdb) exec-file readin
(gdb) run
Starting program: /x/x/x/readin readin
Program exited normally.
valgrind:
HEAP SUMMARY:
==7948== in use at exit: 0 bytes in 0 blocks
==7948== total heap usage: 20,206 allocs, 20,206 frees, 2,661,509 bytes allocated
==7948==
==7948== All heap blocks were freed -- no leaks are possible
code:
....
Flow flw = endQueue.top();
stringstream str1;
stringstream str2;
if (flw.getSrc() < flw.getDest()){
str1 << flw.getSrc();
str2 << flw.getDest();
flw_src_dest = str1.str() + "-" + str2.str();
} else {
str1 << flw.getSrc();
str2 << flw.getDest();
flw_src_dest = str2.str() + "-" + str1.str();
}
while (int_start > flw.getEnd()){
if(flw.getFlow() == 1){
ava_bw[flw_src_dest] += 5.5;
} else {
ava_bw[flw_src_dest] += 2.5;
}
endQueue.pop();
}
Be careful erasing elements from a container while you are iterating over the container.
I believe this will have
pospointing to the next value but then++poswill advance it yet again. Iferase(pos)resulted inpospointing atava_bw.end(), the++poswill fail.I know if you tried this with a vector,
poswill be invalidated.Edit
In the while loop you do
You need to do
flw = endQueue.top()again.