while using the size
command in Unix systems with the executable or object files, we get output in the form of the size of text segment and data segment. Why doesn't it show the output for heap or stack segment? Below is the output of size command
$ size hello_world-1 hello_world-1.o
text data bss dec hex filename
916 256 4 1176 498 hello_world-1
48 0 0 48 30 hello_world-1.o
Heap and stack are applicable to processes, which are (often) executables files loaded by the OS into memory, not to files stored on the file system directly.
Also, stack and heap size can vary during the lifetime of the process, so one could not, in general, predict how much stack or heap a certain executable file will take when loaded as a process.
This is why a command like size
is not designed to show such information in addition to the size of code / data in the file itself.
Because Heap section is used for dynamic memory allocation while the program is running, and the memory will be allocated during run time only because it is dynamic right. And for stack the variables stored there have local scope or block scope only and they also have there existence until the program runs.
And yes this stack,heap,data and code memory sections are in context of the process or the program which is running.
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