Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the size command didn't list a stack or heap segment for any executable or object file?

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
like image 359
Kamal Pandey Avatar asked Apr 11 '18 06:04

Kamal Pandey


2 Answers

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.

like image 96
Pac0 Avatar answered Oct 01 '22 19:10

Pac0


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.

like image 35
Stubborn Avatar answered Oct 01 '22 21:10

Stubborn