默认情况下,将在.net中为对象分配多少内存 [英] how much memory will be allocated to object in .net by default

查看:99
本文介绍了默认情况下,将在.net中为对象分配多少内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



默认情况下.net中对象的大小是多少。我们如何测量它



表示



默认情况下将在.net中分配多少内存?

Hi All,

What is the size of object in .net by default.How can we measure it

means

how much memory will be allocated to object in .net by default?

推荐答案

基本上你不能,如果没有一些相当高级的反射来递归地解析你的类型并获得每个组成部分的大小 - 这可能有他们自己包含的类,这可能......你明白了。



这将是懒散的。



显然还有另一种方式。看看这个: http://blog.softwx.net/ 2013/01 / benchmarking-struct-and-object-sizes.html [ ^ ]它确实完成了工作 - 显然,我还没有尝试过。我对它的准确性有严重的怀疑,因为代码最多会尝试12次才能在同一个对象上获得一致的结果......如果GC不会连续两次告诉你同样的事情,你有什么希望得到的?



.NET的一部分想法是,对于大多数应用程序,你不应该考虑对象的大小 - 只需继续使用它们。
Basically you can't, without some fairly advanced use of Reflection to recursively parse your type and get the sizes of each of it's constituent parts - which may well have their own contained classes, which may... you get the idea.

And it'll be sloooow.

There is apparently another way. Have a look at this: http://blog.softwx.net/2013/01/benchmarking-c-struct-and-object-sizes.html[^] it does do the job - apparently, I haven't tried it. I have serious doubts about it's accuracy, given that the code tries up to twelve times to get a consistent result on the same object...if the GC won't tell you the same thing twice in a row, what hope have you got?

Part of the idea of .NET is that for most applications, you aren't supposed to think about the size of your objects - just get on and use them.

它取决于我们用于该对象的变量和类型等。但默认情况下,8字节将被分配给.net中的对象

通过使用反射我们可以观察到这一点。但我也不知道如何找到它。



但是.net中默认的对象大小是8个字节。
It depends on variables and types and etc what we have used for that object.but by default 8 bytes will be allocated to object in .net

by using reflection we can observe this.but am also not sure how to find out this.

but default size of object in .net is 8 bytes.


这篇关于默认情况下,将在.net中为对象分配多少内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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