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.
In computer programming, the block starting symbol (abbreviated to . bss or bss) is the portion of an object file, executable, or assembly language code that contains statically allocated variables that are declared but have not been assigned a value yet. It is often referred to as the "bss section" or "bss segment".
bss and add almost nothing (about 4–8 bytes for the description) to the executable file size. So the reason for . bss is to have smaller executable, saving space and allowing faster loading of the program, as the loader(startup) can just allocate a bunch of zeros instead of having to copy the data from disk. So .
bss segment stands for Block Started by symbol. The bss segment contains the object file where all the statically allocated variables are stored. Here, statically allocated objects are those objects without explicit initialization are initialized with zero value.
'text' is my code, vector table plus constants. 'data' is for initialized variables, and it counts for RAM and FLASH. The linker allocates the data in FLASH which then is copied from ROM to RAM in the startup code. 'bss' is for the uninitialized data in RAM which is initialized with zero in the startup code.
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
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