I was prepared to write an article to explain in depth what happened to boxing and unboxing, and to explain the CLR thread stack execution model.
Tired, there have been a lot of things recently. I 'd like to agree to answer your questions briefly.
Use a piece of jiaoer code to illustrate the problem:
Namespace msiltest
{
Public struct point
{
Public int X;
}
Class Program
{
Static void main (string [] ARGs)
{
Point P = new point ();
P. x = 1;
Object o = P;
P. x = 2;
System. Console. writeline (p. x + "," + O );
}
}
}
During debugging, the output is 2, msiltest. Point.
Here we will first describe part of the output, msiltest. point is very knowledgeable. By studying the msil code of this program, as well as the implementation of a Concat method of the string class in The Decompilation FCL, and the rewriting of several methods of the class in inheritance, we can understand why msiltest is output. point; of course, if the point is a class and there is only one int attribute in it, the value of the int attribute will be directly output.
Here, P is 2 well understood. we have a breakpoint in the object o = P; line, F5 debugging, and then F10 two steps. at this time, place the cursor over o and you can see that the value of O is 1 rather than 2.
This illustrates a problem. After boxing, the value above the original computing stack is not deleted; boxing just copies this valuetype to the corresponding area of the heap object. the valuetype of the corresponding area of this object is another type of Value Type: boxed type;
At the same time, after a new object containing this value type value is generated, the application of this object is returned to the stack top of the computing stack.
Note that unboxing does not include the copying of values. This is very important.
This involves the equivalence relationship between the three commands in msil.
Is Unbox. what happens under the "any" command is what happens under the "Unbox" command, and what happens with the "ldobj" command. the box command is used to split the box, while the ldobj command is used to copy the value type to the top of the stack.
The unboxing term refers to the operations performed by the box command and does not include the copying of values to the top of the stack. so msil designed an Unbox. the any command is used to complete these two actions. This is a very broad misunderstanding and you must be clear about the difference!
Well, let's talk about the thread stack, computing stack, stack, and stack in a very simple way.
The concept of heap and stack is designed here. Generally, the heap is managed heap. generally, the stack is the computing stack, that is, the stack. in many places, stack is also used to being a stack.
The thread stack involves a lot of things. when a method is executed, an external storage and a local storage area are allocated to it. in the local storage area, a local variable list, a computing stack, and a variable table are allocated. these three items are all required for method execution.
The local storage area is used as a field and is placed on the thread stack together with many methods. each method currently being executed is the top method on the thread stack. after the execution, pointer moves and this method pops up.
All msil commands are stack-based. Each thread is allocated 1 m during allocation, which is identified in the manifest file.
However, I have been wondering for a long time where 0x100000 represents 1 MB ....
One of them is that when we study the Linux operating system to allocate space to threads, The mmcreatememoryarea method specifies the size of the space allocated to a thread, I forgot it after reading it.
You can refer to the article ".pdf" for details.
Well, it's a little simple to answer your questions. Sorry, I didn't write details about many things. It takes several thousand words to illustrate it.
I am tired recently and have a lot of things. I don't know if I have made it clear to jiaoer.
Well, given that there are few msil studies and incomplete documents in China, we may write a series of <msil via CLR>. It is estimated that there are a lot of words to expect.
Next blog Study: PE files under. net