当前位置: 动力学知识库 > 问答 > 编程问答 >

c# object lifetime. where the retrieved value of pointer is used

问题描述:

mabby it is a silly question)

i have a small misunderstanding:

"newobj" makes the CLR to:

1) calculate how much memory the object need

2) if the heap has enough memory - invoke a constructor,

retrieve a link of the new object in memory to the main code

(the adress is the last position of pointer to the next object)

3) BEFORE! the reference is retrieved move pointer to the next object

here is an example:

Car myCar = new Car;

so, if i understand, the compiler write the "link to the next object"

into myCar ?? if we need the compiler to write the "link to our object"

into my car..

if You can, please describe how it really works

网友答案:
Car myCar = new Car;

Invoked a constructor of Car type, with invokation chain of all parent types begining from the deepest one.

Space is allocated, pointer obtained to that memory location and address of that memory assigned to myCar.

Basic steps

分享给朋友:
您可能感兴趣的文章:
随机阅读: