C + + Essay: GC exploration of. NET CORECLR (3)

Source: Internet
Author: User

I haven't written GC-related articles in a few days. The way I speak GC today is explained by a small sample code that only has a successful build. The address is D:\coreclr2\coreclr\bin\obj\Windows_NT.x64.Debug\src\gc\sample, and the prefix path is OK for everyone to replace it with their own path.

First, let's start with the main function. The first is the initialization of the GC.

int __cdecl Main (int argc, char* argv[]) {    /////    Initialize System Info    ////Initialize GC, if initialization fails, exit directly if    (! Gctoosinterface::initialize ())    {         return-1;    }

Next we look at Gctoosinterface this class, I just put the part of the method listed, we can understand this as "interface", these methods, also applied to the design pattern, such as the following method of naming, is not like EF? After all, it is Microsoft's things, you can understand, are a pro. In addition, the allocation of virtual memory is not as simple as we think, it is also a thing, for a thing, its method is rich.

Interface that the GC uses to invoke OS specific FUNCTIONALITY//GC and the operating system bridge, you can understand the method of invoking a specific "method" of a particular operating system class Gctoosinte Rface{public:////initialization and shutdown of the interface//Initialize and turn off GC for OS (OS) interface//Initialize the I     Nterface Implementation//Return://True if it has succeeded, false if it has failed static bool Initialize (); Shutdown the interface implementation//to terminate this method; A simple understanding is.    The Dispose () method in the. Net.    static void Shutdown (); Vsan Management////Virtual memory Management//reserve virtual Memory range.//storage Range//Parameters://AD  Dress-starting virtual address, it can be NULL-let the function choose the starting address//Size-size Of the virtual memory range//alignment-requested memory Alignment//Flags-flags to control special set Tings like write watching//Return:///Starting virtual address of the reserved range//parameter://address (Address)-the original, If NULL, allows the method to select the initial address;//size (size)-VirtualMemory range definition domain;//alignment (queue)-The requested storage queue//flags (identifier)-identity control (for example, write, observe, or read);//return: The first address of the stored virtual memory; static void* Virtualreserve    (void *address, size_t size, size_t alignment, uint32_t flags); Release virtual memory range previously reserved using virtualreserve//releases a defined domain, note that this definition field is the defined domain of the virtual memory allocated before;//Parame Ters://address-starting virtual address//Size-size of the virtual memory Range//Return://Tru E If it has succeeded, false if it has failed//return-success: TRUE, otherwise: FAIL static bool Virtualrelease (void *address, size_t si    Ze); Commit virtual memory range. The It must is part of a range reserved using virtualreserve.//to commit the defined domain of virtual memory; Note that the submitted definition field must be a block of memory that is included in the "Virtualreserve allocated". Note that the commit here can be understood as. NET and SQL "transactions"/////////////////////Parameters//Size-size of the virtual memory ran GE//Return://True if it has succeeded, false if it has failed static bool Virtualcommit (void *address, Size_    t size); Decomit Virtual MemoRy range.//revocation Submission-and the Virtualcommit function is just the opposite;//Parameters://address-starting virtual address//Size-size Of the virtual memory Range//Return://True if it has succeeded, false if it has failed static bool Virtualde Commit (void *address, size_t size);}

Let's take a look at the Initalize method, what does it mean to query the performance frequency first?

BOOL Gctoosinterface::initialize () {//query performance Frequency    if (!::queryperformancefrequency (&performancefrequency))    {        return false;    }}

I notice the constant of the performancefrequency, and look at its definition:

Static Large_integer performancefrequency;

Again see Large_integer, found is a consortium, I here Science a consortium, do not trouble everyone to other places to find information.

-------------------------------------------------------------Split Line Start------------------------------------------------------- -----------------

    1. 1. Multiple members can be defined in union, and the size of the Union is determined by the size of the largest member.
    2. 2. Union members share memory of the same block size and only one member can be used at a time.
    3. 3. Assigning a value to a member overrides the values of other members (not surprisingly, because they share a piece of memory.) but only if the member has the same number of bytes, when the number of bytes of the member does not only overwrite the value on the corresponding byte, such as assigning a value to a char member will not overwrite the entire int member, because Char occupies only one byte and int is four bytes.
    4. 4. The order in which the Union union is stored is that all the members are stored from the low address.

-------------------------------------------------------------Split Line End------------------------------------------------------- -----------------

If Midl_pass is defined, though I do not know what this is # if defined (midl_pass) typedef struct _LARGE_INTEGER {#else//Midl_passtypedef Union _ Large_integer {    struct {        DWORD lowpart;        LONG Highpart;    } Dummystructname;    struct {        DWORD lowpart;        LONG Highpart;    } u; #endif//midl_pass    longlong QuadPart;} Large_integer;

The above people need to understand some basic knowledge of C + +, specific people to Baidu, the following we look at QueryPerformanceFrequency this method, this method is located in the WDK, detailed introduction to see here

    • typedef unsigned long DWORD;
    • typedef long Long;
    • typedef __int64 Longlong;
Winapiqueryperformancefrequency (    _out_ large_integer * lpfrequency    );

Take a look at the complete method, want to study in-depth, you can self-study ~

BOOL Gctoosinterface::initialize () {//query performance Frequency    if (!::queryperformancefrequency (&performancefrequency))    {        return false;    } System Information    System_info systeminfo;//This method is located in WDK8.1    GetSystemInfo (&systeminfo);//gcsysteminfo, The system information is obtained through the WDK, and then the information is assigned to gcsysteminfo    g_systeminfo.dwnumberofprocessors = systeminfo.dwnumberofprocessors;    G_systeminfo.dwpagesize = systeminfo.dwpagesize;    g_systeminfo.dwallocationgranularity = systeminfo.dwallocationgranularity;    return true;}


C + + Essay: GC exploration of. NET CORECLR (3)

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.