what's the utility of bss segment?

295 views Asked by At

I know that bss segment contains uninitialized variables which will be given 0 as initial value,but why we don't just use the data segment to store them?

I read that it speed up execution because the os loader initialize all these variables at once by calling memset, however, I'm not very convinced because the loader can call memset to initialize them in data segment also!

1

There are 1 answers

3
Mehrdad Afshari On

Because you might have a huge set of uninitialized values. You will have to fill the binary with zeros (or any value, for that matter, but something has to be there) if you were to use the data section for that purpose. Imagine adding a megabyte of zeros to the executable file...