![]() |
Seemingly random combination of statements causes segmentation fault (C++)
Hi, I'm trying to figure out what's going wrong in a simulation I'm writing. It probably has something to do with the lot of big arrays. I can get it down to the following:
Code:
#include <iostream>I have no idea what's going on here..:confused: |
You are using too much memory on the stack. Maybe getting a random number somehow causes it to try to use memory on the stack, or something, which actually causes the segmentation fault; whereas maybe otherwise it doesn't try to use memory on the stack.
|
So maybe I should just try sticking some of those arrays on the heap (free store)? And hope it goes away? (stack, heap, I can't keep these names straight)
|
The loader ld.exe reserves 2Mb of stack, so with two arrays you come in just under the threshold, but with the third array you exceed the limit. This can be changed by using the --stack option of the loader. see man ld. However if you are linking through g++ then you will probably need to use the following switch
-Wl,--stack=0x0800000 for 8Mb of stack memory. |
| All times are GMT -5. The time now is 11:31 AM. |