Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the maximum memory allocated on the stack/heap

Tags:

  • 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?

like image 995
Computernerd Avatar asked Dec 19 '12 02:12

Computernerd


2 Answers

In Visual C++ you may use directive #pragma. For example:

#pragma comment(linker, "/STACK:2000000") #pragma comment(linker, "/HEAP:2000000") 
like image 60
VeLKerr Avatar answered Sep 25 '22 08:09

VeLKerr


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.

like image 35
Joseph Quinsey Avatar answered Sep 26 '22 08:09

Joseph Quinsey