Tuesday, June 27, 2006

.bss ???

What is a BSS segment?

Most of the guys ask me this question. This is some segment in your application similar to .text, .data and .stack. All the un-initialized variables go into this section, rather than .data segment. This is to reduce the size of your .exe or .o files.

For example, if you have declared a variable "int a", it goes into the .bss segment. The compiler will not allocate space for "a" in the executable file. Instead, it will accumulate such variables and calculate the total number of bytes and add it in the header.

So your application will not have the space allocated, when it is in secondary memory. Once it is loaded into the primary memory, the number of bytes for the .bss segment is read from the header and allocated in RAM.

- Alexander.