When I try to initialize a 3D array of size 300*300*4 in a C program, my program stops running and reports stack overflow error. The system I am using has 3GB RAM, which should be sufficeint. Is there any way to increase memory allocated to a program? I am using Dev C++ on Windows Vista.
Allocate RAM Using Windows Task Manager On your Windows 10 PC, open the Windows Task Manager app. To do so, use your keyboard's CTRL + SHIFT + ESC buttons. Go to the “Details Tab.” Right-click on the application you wish to assign extra RAM to and select priority.
Either use malloc()
/free()
(or new[]
/delete[]
for C++), or a global array, or a local static array. If you try to create a non-static array within a function, it gets allocated on the stack and stacks are generally not very large.
You can also try initialising the array backwards; some OSs grow the stack dynamically as page faults occur, and since on x86 the stack grows numerically downwards, initialising backwards can help.
You need to increase how much stack space your program can use.
You can set the maximum stack size in the properties dialog under to "Linker | System | Stack Reserve Size"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With