Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase memory allocation to program

Tags:

c++

c

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.

like image 966
Vaibhav Avatar asked Jun 12 '10 06:06

Vaibhav


People also ask

Can I allocate more memory to a program?

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.


2 Answers

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.

like image 172
Artelius Avatar answered Sep 30 '22 10:09

Artelius


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"

like image 35
R Samuel Klatchko Avatar answered Sep 30 '22 10:09

R Samuel Klatchko