类的内存分配 [英] Memory allocation of a class
问题描述
只是想让我的基础知识正确.如果我声明一个带有字符串变量,一个int和一个数据表的类,并实例化它将消耗多少内存.
Hi,
Just trying to get my basics right. If I declare a class with a string variable, an int, and a datatable and i instantiate it how much memory it will consume.
class A
{
private int i;
private string s
public int ii
{
get; set;
}
public string ss
{
get;set;
}
}
class B
{
A obj = new A();
A.ii = 23;
}
在这里,我想知道实例化类(A obj=new A();
)时将分配多少存储空间.现在,当A.ii=23
时将为该类分配多少内存.可以容纳一些内存的未分配的字符串变量有什么作用(我不记得字符串是否有最大字节限制).
提前谢谢.
afsal
Here I would like to know how much memory space will be allotted when I instantiate the class( A obj=new A();
). Now how much memory will be allotted to the class when A.ii=23
. What is the effect of an unassigned string variable which can hold some memory ( I don''t remember if there is any maximum byte limit for string).
Thanks in advance.
afsal
推荐答案
您也可以看看这里 [ ^ ]来衡量内存使用情况.
You can also have a look here[^] to measure memory usage.
您可以使用工具 memprofilter [
You can use the tool memprofilter[^]. I hope response to your question.
这篇关于类的内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!