[C #] CLR memory (advanced ),

Source: Internet
Author: User
Tags class manager

[C #] CLR memory (advanced ),

For this article, I don't want to discuss the value type any more. For example, we can take a look at the memory of the value type (the first thing about CLR memory). We will mainly discuss the reference type in this article.

Two types of equipment first

 internal class Employee    {        public static Employee LookUp(string name)        {            return null;        }        public virtual string GetProgressReport()        {            return string.Empty;        }    }    internal class Manager : Employee    {        public override string GetProgressReport()        {            return string.Empty;        }    }

 

In the Employee class, there is a virtual method GetProgressReport and a static method LookUp. The Manager class inherits the Employee and overwrites the GetProgressReport.

     static void Main(string[] args)        {            Employee e = new Manager();            e = e.LookUp("Tom");            e.GetProgressReport();        }

We can write such code in Main to see how stacks and stacks work.

When the JIT compiler converts these IL code to local CPU commands, it will notice all types: Employee, Manager, String (due to Tom String ).

1. Before running the method, the "prologue" code will open up space for these objects in the memory.

2. employee e = new Manager (); will press e into the stack and save the Manager object address. As we said in the first article, each object has a synchronized block index and type object pointer, which is the address of storage.

3. e = Employee. LookUp ("Tom"); when calling a static method, CLR locates the type object corresponding to the type that defines the static method. Then, the JIT compiler searches for the record items corresponding to the called method in the method table of the type object, compiles the method with JIT (if necessary), and then calls the Code Compiled by JIT. At this time, we know that the returned LoopUp is the Employee object (at this time, the Manager object I created at the beginning is not sure whether it has been cleared, because the GC will automatically clean up the managed code ), therefore, open a memory block of the Employee on the heap and change the address of e to the position of the Employee object.

 

Note: both Employee and Manager objects contain "type pointer object" members. In this case, the type object is essentially an object. When creating a type object, CLR must initialize these members. What is initialization? When CLR starts running in a process, it immediately creates a special Type object for the System. Type defined in MSCorLib. dll. Both the Employee and Manager types are "instances" of this type. Therefore, their Type object pointer members are initialized to reference System. Type objects.

By the way, the address stored by "type pointer Object" is returned by Object. GetType.


Whether c + c = 2c is correct or wrong

Hello. C + c = 2c is completely correct for pure mathematical calculation questions.

However, the world is big, and there is no wonder. C + c = 2c if mathematical computing is not taken into account

[C + c = 0]
This type of person is suitable for personnel work. One person can be used to deal with another person, and his/her own profit is profitable. There are not many real friends.
[C + c = c]
This type of person has the advantage of coordination and cohesion, which can turn two people into a rope and is suitable for leaders.
[C + c = 3c]
Such a person must be a good husband and a good wife, and be happy to marry such a person.
[C + c> 2c]
Such people can discover the advantages of each thing, exert limited power to the infinite, and be politicians and military strategists.
[C + c = cc]
This type of person has a good perceptual knowledge and a clear understanding of the problem. The solution to the problem may be informal but effective.

What is CC?

Many abbreviations
It can also be the name of the heroine of the rebellious luch.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.