Think of the work of the program loader. To load a program it has to
basically do the following.
1. Allocate memory for the program executable code and load the code
from the executable file into that space.
2. Allocate memory for a stack.
3. Allocate memory for program data - say 300 bytes are needed of
which 200 have initial values and 100 are not initialised. It loads
the first 200 bytes of initial values from the executable file. The
remaining 100 bytes have no initial values so they are not part of the
executable file but there still needs to be space allocated for them
when the program runs. The last 100 bytes is the bss section.
The need for both predefined data and uninitialised data can be seen
in the these two statements. Think of them as global or static.
float a = 53.0;
float b;
Variable a and others like it which have an initial value will be
assigned to the data section. Variable b and others which are not
initialised are assigned to bss. Since values in bss are not specified
the compiled code does not need to specify initial values for them,
they don't need to take up space in the executable file and the
program loader doesn't need to spend time loading them from disk.
No comments:
Post a Comment