Now when I have this list what I'm gonna do is I'm going to store in a variable let me see a size of
list.
Size of list OK and size of list is available.
And I'm going to get the size by using the size get size or function.
If you remember the get size of function from the system or do I have color size and I'm going to use
that function now and I'm going to say size often I'm going to pass the LSD right.
OK.
Let me just print size of list so I'll print size of this.
And all I can say.
Come on.
Sorry.
Size of list.
And there we are.
So size of list is 88.
Now comes the question.
Is this the total size of the list.
Is this a total totalist the size of a list of cause of just three elements is eighty eight bytes.
OK that's fair enough.
But is this the size of the list or is this the size of these three elements along with the list or
is there more to a list let's understand.
Let's first take an empty set.
Let me call it as an empty empty LSD and emptiness What is the size of an empty list.
Let's have a look.
So I'm going to say size of empty suit
is equal to size of.
And then I can use the list I can pass that into though and then I can of course print up the size of
empty list
right.
So the size of the empty list itself without any of these elements is 64.
Which means each each element inside this list takes takes how much.
88 minus 64 that is.
That is we have 24:24 divide by three that is it by each.
So 64 bytes is for an empty list 8 bytes each for each element in this list.
Eight bytes each for each element in this list right now if I dive further if I ask you further what
are these elements what are these elements.
Are there elements directly or are the objects.
Or are there references to an object.
If you remember in Python none of these are elements.
None of them are values itself.
They are references to objects.
Right.
How do I come to know that if I print the type of of LSD of zero.
That's the first element if I print the type of that it is class Integer which means this is a reference
to an object of type class Integer.
So that means the size which we have got here is an empty list size plus another 24 bytes.
Those 24 bytes does not belong to the exact element the values they actually belong to.
They actually belong to not just Elliman values but they belong to the references to an object.
So that means the size of each of these elements will be.
Is is it added the size of this is this a reference to the list.
Basically when I say size of list this is best in the memory space that is going to create a list which
is going to have some overhead data of 64 bytes along with as many number of elements then along with
the corresponding to those number of elements.
There will be number of references.
Those references are stored in 64 bytes.
So in 24 bytes right.
For each element.
Ed bitis taken to sort of reference but those reference are nothing but pointing to another.
It's a completely different.
Those references are finally pointing to pointing to elements of type integer.
Right.
So that means each of the elements in this list finally have more more size.
That means if I would say size of LSD of zero size of LSD abse you this will give me the actual size
of each of the elements more than the differences.
OK.
So the size of each element this word granted.
So if I say total size total size when you define a list total size when you define a list will be first
of all the size of list as we just saw over here the size of list but also along with that the size
of each elements plus.
OK so maybe just before this I can just you know I can just keep this aside and I can say I can just
define size of each element.
Enlist right each element.
Let me just put that up in you of each element and that can be size of LSD of zero.
Right.
LSD of zero and that's size of each element.
Now if you want to print it of course you can have size of each element being printed that's 28 we already
saw that.
But total size is going to be that size which is going to be equal to the size of list plus plus the
Lenn all lendin all I can say of each the length of the total number of you know total number of elements
in the list I can get that with Lanuf LSD and then multiply that size of each element right size of
each element.
And this would be the total size so if I print the total size this is going to be total size.
So you can have a look for a list of three elements the total size is 172.
Wow.
That's a size of all the memory consumption in the list the memory consumed in the list is actually
the total size is the list size of the entire list plus the size of each element because the size of
the list only consists of references of objects whereas each object has its own size multiplied by the
number of objects in the list.
So total size will be 172.
That's the total in memory consumed by a list.
Now let's go want to figure out what will be the memory consumed in an empty attic right.