这里的堆值是多少? [英] what is heap value here?

查看:121
本文介绍了这里的堆值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的堆值是多少?再次有一些东西要知道它在内存中的步骤???我尝试了很多次,最后据我所知,它可以是x的值,基本上是"Hello World!"

非常感谢

what is heap value here ? again something to know how its steps in memory ??? i tried alot and at last i get by my knowledge it can be value of x which is basically " Hello World !"

many thanks

class MyClass
{
    String M = " ";

    public MyClass(String message)
    {
        M = value;
    }
}

MyClass X;
X = new MyClass(" Hello World! ");

推荐答案

很难弄清您想知道的内容,但希望我能回答您的问题. ..

忽略那些无法编译的问题,并且需要进行相当多的更改以执行您想要的操作(我怀疑),您也有一些错误的想法.

如果我稍微修改一下您的代码:
It''s hard to work out what you want to know, but hopefully I have got the gist of your question...

Ignoring that that won''t compile, and needs a fair number of changes to do what (I suspect) you intended it to, you have got the wrong idea a bit as well.

If I fix your code a little:
class MyClass
{
    public string M = " ";
 
    public MyClass(string message)
    {
        M = message;
    }
}
 
MyClass X;
X = new MyClass(" Hello World! ");

(哪处都不是完美的,但是您稍后会加以改进-我只想解释哪里去了)
该代码在堆上创建三个项目:
1)包含空格的字符串
2)包含"Hello World!"的字符串.
3)MyClass的类实例

当您使用new关键字调用MyClass构造函数时,将构造参数字符串实例,然后为该类实例分配空间,最后构造其字段,因此为包含空格的字符串分配空间.然后调用构造函数的代码,并使用参数字符串引用覆盖字符串字段M引用. (如果没有图片,这很难解释,但希望您能明白.)


(是的,纯粹主义者,琴弦很特别-让它暂时骑行,好吗?不要混淆可怜的灵魂!)

(Which is no where near perfect, but you''ll improve it a bit later - I just want to explain what goes where)
The code creates three items on the heap:
1) A string containing a space
2) A sting containing " Hello World! "
3) A class instance of MyClass

When you call the MyClass constructor by using the new keyword, the parameter string instance is constructed, and then space is allocated for the class instance, finally it''s fields are constructed, so space is allocated for a string containing a space. The code of the constructor is then called and the string field M reference is overwritten with the parameter string reference. (This is hard to explain without pictures, but hopefully you will get the idea).


(And yes, purists, strings are special - let it ride for the moment, ok? Let''s not confuse the poor soul!)


这篇关于这里的堆值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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