Reputation: 345
In C++, we all know the array can be in the "main" scope as the local variables:
int main(){
int arr[10000]; //on the stack, size can't be very large
....
}
or out of the "main" scope as global variables:
int arr[10000000]; //on BSS, sie can be very large
int main{
....
}
but I want more for this problem.
Upvotes: 6
Views: 2094
Reputation: 705
The stack size for the main thread is allocated by the operating system at process creation time. On linux, you can inspect and change it with the command 'ulimit'. To get a list of current process creation limits:
ulimit -a
On my Linux x64, the default is:
stack size (kbytes, -s) 8192
If your program creates any threads, each thread will also have their stack size set to a default value (2048k on linux/pthread) which you can change using the function:
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
For the BSS size, the limit is how much virtual memory your process can access: 1.5-2g on a 32bit machine and approximately 2^b on a 64bits one. Note that 'b' is not necessarily 64:
cat /proc/cpuinfo
On my old server gives:
address sizes : 36 bits physical, 48 bits virtual
Upvotes: 1