有关使用任何动态集合类型进行池化的怀疑. [英] Doubt regarding Pooling using any dynamic collection type.

查看:64
本文介绍了有关使用任何动态集合类型进行池化的怀疑.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// initial capacity = 100000

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

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



案例1.

如果我刚刚在我的应用程序中初始化并创建了上面的Queue实例,但未使用它(未在其中添加任何元素),那么这意味着在不添加任何元素的情况下,它最初仍将占据size = ClassA-Size * 100000 .

案例2.

如果使用的Type是Interface类型,那我们什至都不知道大小,因为实现它的任何类都可以具有不同的大小.


如果我错了,请纠正我,因为我很困惑.



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.

推荐答案

在两种情况下,muQueue1变量的大小都相同.它包含对对象的100000个引用,而不是实例本身.

当添加100000个ClassA实例时,muQueue1的大小仍然相同.您的总内存使用量为100000 * ClassA的大小+ muQueue1的大小.

添加从ISomeInterface派生的类的100000个实例时,情况相同. myQueue1仍然具有相同的大小.您的总内存使用量是muQueue1的大小+您添加的所有派生对象的总大小.

问候
Piet
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


这篇关于有关使用任何动态集合类型进行池化的怀疑.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆