On 29 Jun 2000, Ulrich Drepper wrote:
> > Only in sloppy C implementations. Initializing a variable *to zero* does
> > not put it into .data if the implementation is being sensible. Only
> > variables initialized to non-zero values need to be in the .data section.
>
> If an implementation does it it is completely broken since it would
> prevent you from having an initialized variable with value zero
> without using hacks like a section attribute.
Huh? Please explain. Variables in .bss are not left uninitialized! To
the program, there is *no* difference, none whatsoever, between a variable
in .bss and a zero-initialized variable in .data. Both have a guaranteed
initial value of zero. So it's perfectly reasonable for an implementation
to notice that an explicitly-initialized variable has been initialized to
zero, and put it in .bss.
> No. The possibility that you have to map in another page increases by
> sizeof (var) * 100
> --------------------
> pagesize
> with every variable. Even a single of one byte can make a difference
> if it will end up alone on a new page.
If you have (say) 100 bytes of such variables, and a 4KB page, the chance
of needing *one* extra page is under 2.5%. That is, perhaps one program
in every forty will actually need the page. This is less variation --
much less -- than that produced by other factors, such as changes in
levels of compiler optimization. The circumstances in which this is worth
caring about are few and far between.
> > ...The only difference is that .data must be
> > initialized from a disk copy, while .bss can be initialized by a CPU loop.
>
> Can be initialized by a CPU loop which is run in the OSes idle time!
There's no question that initializing a .bss page is cheaper than
initializing a .data page. But programmer time -- spent in reading or
modifying a program -- is much more expensive than either. In most
situations, optimizing programs for readability is preferable to trying
to save a few bytes per binary.
Henry Spencer
[EMAIL PROTECTED]
-
Linux-UTF8: i18n of Linux on all levels
Archive: http://mail.nl.linux.org/lists/