This is a very simple example where I have an array which is of size 20,000 are present in a global
variable.
So this will be going to the data section.
And I'll compile this one.
And.
And see the size of this one.
This is almost 95 KB.
So very simple code, which has an array of uh 20,000 bytes is having 95 KB.
Now I have an updated one more code.
I just do not initialize this thing.
This array.
Here I am initializing first three bytes of an array.
But here first three members of an array.
Here I am not initializing them.
Now when I compare this one and I will check the size of.
This one.
I'm taking this as a first one.
Taking this as a second one.
This one is 17 KB.
So huge difference between two files, right?
Uh, where the code is almost same.
Only thing I am not.
I am initializing here and I am not initializing here.
But the size is huge like 17 kb and 95 KB.
Can you understand why we have the huge difference in the size file?
So let's list all the headers.
Uh, let's list all the sections.
So user space one.
It has 28 sections and user space two it has 28 sections.
So there is no change here.
Let's see the user space one.
And Griff for only the BSS.
And now user space two and Griff for basis.
And if you see any difference here size uh so the type address offset size.
So it is like five fifth entry.
So if you see the difference here the basis is having only eight bytes in the this code where we have
initializing.
So there is no basis uh because we have not even not having uninitialized variables.
But when it comes to this user space, two you have BSS section.
Uh, because we have not initialized, all this code will be going to the BSS section and the size is
increased, but the size of the file is not increased, it just increased.
It has added information saying I need a basis of this particular size.
Now let's print uh user space one.
And for basis.
So it is present in this particular fifth location.
And here 012345 if you see file size and mem size are nearly same, extra eight bytes are added.
Now if I say user space two.
And if you see this file size, the size of the user section, which is uh, this particular segment
size of this particular segment, which includes the BSS section, is only this much.
But when it comes to the memory, this is huge.
So BSS section will not be present in the Elf file.
Only the information about how much size we need to add to the memory is present in the section on the
segment, but actually we are not having zero block of section present in the Elf file, so it is saving
the memory space.
The disk space is reduced, but when it goes to the memory the we are creating this much size.
So that's this is only one place where you can see the file size is less and memory size is more because
of the BSS.