How can one increase the maximum memory allocated on the stack/heap for a program in C++?
Will increasing the RAM of your computer automatically increase the stack/heap memory of a computer program?
In Visual C++ you may use directive #pragma
. For example:
#pragma comment(linker, "/STACK:2000000") #pragma comment(linker, "/HEAP:2000000")
Second edit: I see from your comment that you work in Windows, so my Unix answer below would not be very helpful to you. But see Determining Stack Space with Visual Studio and C/C++ maximum stack size of program.
The stack size is quite often limited in Linux. The command ulimit -s will give the current value, in Kbytes. You can change the default in (usually) the file /etc/security/limits.conf.
You can also, depending on privileges, change it on a per-process basis using setrlimit()
. See for example my answer to Segmentation fault: Stack allocation in a C program in Ubuntu when bufffer>4M.
For heap, see e.g Heap size limitation in C. But I don't believe you can increase or decrease the maximum 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