1
$\begingroup$

Are data segments,heap,stack etc also present in secondary memory with compiled code then later mapped by OS to RAM when I open it?

$\endgroup$
  • 1
    $\begingroup$ If you declare a variable but never use it, most compilers will ignore it entirely. What scope are you declaring the variable in, and what are you doing with it? This might also be better-suited to StackOverflow, depending what sort of answer you want. $\endgroup$ – Draconis Oct 8 '18 at 6:00
1
$\begingroup$

Under most operating systems the binary executable and object files stored on disk contain three segments:

  1. the .text segment (the code)
  2. the .data segment stores the initial value for any global and static variables that need to be initialized to specific values other than zero.
  3. the .bss segment stores the global and static variables that don't need to be initialized, or are initialized to 0. Typically only the size of the .bss segment is stored since the loader can easily create a segment in RAM of this size and fill it with zeros without wasting the time and disk space to store a bunch of redundant information in the executable stored on disk.

The wikipedia page https://en.wikipedia.org/wiki/Data_segment#Data gives some examples.

The stack and heap are typically not stored in the binary executable. They are set up by the loader in RAM when the program is started.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.