Relationship between hosted C ++ and non-hosted C ++

Source: Internet
Author: User

Hosting C ++ is. it advocates a new programming concept, so we can regard "hosting" as ". ", the C ++ application caused by the concept of hosting consists of three parts: hosting code, hosting data, and hosting.

The. Net environment provides many core RUNTIME services, such as exception handling and security policies. To be able to use these services, you must provide some information code (metadata) to the runtime environment, which is the managed code. All C # and VB. NET, JScript. NET is hosted by default, but Visual C ++ is not hosted by default. You must use the command line option (/CLR) in the compiler to generate managed code.

Managed Data is closely related to managed code. Managed Data is the data allocated and released by the garbage collector running in the public language. By default, C #, Visual Basic, and JScript. NET data are hosted data. However, by using special keywords, C # data can be labeled as unmanaged data. Visual C ++ data is not hosted by default, even when the/CLR switch is used.

Although Visual C ++ data is not hosted by default, when using hosted C ++ extensions, you can use the "_ gc" keyword to mark the class as a hosted class. As shown in the name, it indicates that the memory of the class instance is managed by the garbage collector.

In addition, a Managed class can also be. NET Framework members, which can bring about the benefit that it can correctly perform operations with classes written in other languages, for example, hosted C ++ classes can be inherited from Visual Basic classes. But there are also some restrictions, such as hosting classes can only inherit from one base class.

It should be noted that in a hosted C ++ application, both managed classes and unmanaged classes can be used. Figure 1 illustrates the relationship between them.

It can be seen that in managed C ++, managed classes and non-managed classes can use their respective features, but managed classes can be encapsulated.. NET Framework, and use it to the maximum extent.. NET Framework. The traditional C ++ classes are designed using MFC and ATL to compile Windows-based applications.

In addition to the above services and functions, the Microsoft. NET Framework also provides ASP. NET-based network services. These services help simplify development code and improve application reliability .. The. NET Framework includes a set of class libraries that can be used by developers in any programming language. Many application templates are built on them. These templates provide advanced components and services for the development of network sites and networks.

In addition to hosting, the Microsoft. NET Framework also introduces the concept of Assembly. A combination is a group of resources and types, including metadata about these resources and types, that is, a Module ). Metadata contains information such as types and resource tables.

This information can be called outside the assembly body. The metadata also includes information about the subordination, such as the version number when the combination body is created. Developers can specify a version policy to indicate whether the runtime language is loaded into the latest version of the system that depends on the combination.

The combination body can be private to an application or shared by multiple applications. Multiple versions of a combination can be configured on the same machine at the same time. The application preparation Information defines the method for searching the combination body, so that Runtime can load different versions of the same combination body for two different applications running at the same time, this eliminates problems caused by incompatibility of component versions and improves the overall stability of the system.

  1. Differences between standard input implementation methods in C and C ++
  2. How does the C ++ compiler allocate storage space for Const constants?
  3. Basic Conception and method of C ++ Class Library Design
  4. Several Methods for converting C ++ Language
  5. How to better compile C ++ code

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.