Click here to Skip to main content
15,915,094 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
// initial capacity = 100000

Queue<ClassA> muQueue1 = new Queue<ClassA>(100000); // Case I

Queue<ISomeInteface> muQueue1 = new Queue<ISomeInteface>(100000); // Case II


Case 1.

If i have just initialized and create the above instance of Queue in my application but not using it (not adding any elements in it), than does it means that without adding any elements in it will still initially occupies size = ClassA-Size * 100000.

Case 2.

What if the Type used is of Interface type, than we don't even know the size, as any class that implements it can have different size.


Please, correct me if i am wrong, as i am confused.
Posted
Updated 10-Feb-12 20:58pm
v2

1 solution

In both cases the muQueue1 variable has the same size. It holds 100000 references to a object, not the instances itself.

When you add 100000 instances of ClassA muQueue1 has still the same size. Your total memory usage is 100000 * size of ClassA + size of muQueue1.

The same when adding 100000 instances of classes derived from ISomeInterface. myQueue1 has still the same size. Your total memory usage is size of muQueue1 + the total size of all derived objects you have added.

regards
Piet
 
Share this answer
 
Comments
himanshu24x7 11-Feb-12 6:10am    
That was great, i forget that it will keep the reference and not the actual instance.
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900