Perfect C ++: C ++/CLI

Source: Internet
Author: User

What is C ++/CLI? C ++, of course, refers to the C ++ language invented by Bjarne Stroustrup In the BELL lab. It implements a static object model with optimized speed and size during runtime, however, in addition to heap allocation, it does not support dynamic program modification. It allows infinite access to the underlying device, but it is almost impossible to operate the activity type while the program is running, and cannot operate the underlying structure associated with the program. Herb Suter, one of the main constructor of C ++/CLI, said C ++ is a "concrete" language.

CLI refers to the general-purpose language structure, a multi-structure that supports the dynamic component programming model. In many cases, this represents a mode completely reversed from the C ++ object model. A real-time software layer that effectively executes the system and runs between the underlying operating system and the program. The device at the underlying layer of the operation is limited. The activity type in the Operation execution program and the lower structure associated with the program are supported. The backslash (/) represents the binding of C ++ and CLI. The details of this bundle are discussed in this article.

Therefore, the initial and closest answer to the question "What is C ++/CLI" is: it is the binding of static C ++ object models to dynamic component object programming models of CLI. In short, it is how you program in. NET with C ++, rather than C # Or Visual Basic. NET. Like C # And CLI itself, C ++/CLI is being standardized under the auspices of ECMA (European Computer Manufacturers Association) to ultimately comply with ISO standards.

Real-time universal language (CLR) is a Microsoft version of CLI. It is very suitable for Microsoft Windows operating systems. Similarly, Visual C ++ 2005 is the implementation of C ++/CLI.

As the second approximate answer, I THINK C ++/CLI is. the combination of the NET programming mode and C ++, just as the generic programming that was previously generated by combining the template with C ++. In all such combinations, the investment of C ++ owned by enterprises and the experience of developers using C ++ will be saved, this is precisely the important basis for development using C ++/CLI.

How to Learn C ++/CLI

The design of the C ++/CLI language involves three issues, which are also implemented in all other programming languages: the first is the ing of language-level syntaxes to the underlying general type System (CTS); the second is the selection of the underlying detailed structure of the CLI provided to program developers; third, the direct support beyond CLI provides additional functional functions.

The first one is roughly the same for all CLI languages, and the second and third are different and different for different CLI languages. Depending on what issues you need to solve, you may choose one or another language or use multiple CLI languages in a hybrid manner. Learning C ++/CLI involves understanding all these aspects of the design process.

  Ing from C ++/CLI to CTS?

It is very important to use C ++/CLI to program time to understand the underlying CTS. CTS includes the following types of common classes:

1. multi-state reference type, which is used for all inheritance classes.

2. Non-polymorphism value types, which are used for real-time and efficient specific types, such as numerical types.

3. abstract interface type, which is used to define an operation set. It can also be used to implement the reference or value type set of the interface.

This design problem maps CTS to a set of built-in data types in the language. It usually runs through all CLI languages, although the syntax of different CLI languages is different. Therefore, you may write this in C:

abstract class Shape { ... } // C#
Defines a Shape base class from which geometric objects will be exported. However, in C ++/CLI, you will write the following:

ref class Shape abstract { ... }; // C++/CLI
The above code illustrates the underlying C ++/CLI reference type. The two declarations mean the same in the internal layer. Similarly, you write this in C:

struct Point2D { ... } // C#
To define a specific Point2D class, but write this in C ++/CLI:

value class Point2D { ... }; // C++/CLI
The type set supported by C ++/CLI represents the synthesis of CTS and local devices, which determines your syntax selection, for example:

class native {};
value class V {};
ref class R {};
interface class I {};

CTS also supports a slightly different list type from the local list type. Of course, CTS supports both of the above two. For example:

enum native { fail, pass };
enum class CLIEnum : char { fail, pass};

Similarly, CTS supports its own array type, and it once again distinguishes it from the local array in terms of behavior. At the same time, Microsoft once again provides support for these two types.

int native[] = { 1,1,2,3,5,8 };
array<int>^ managed = { 1,1,2,3,5,8 };

It is inaccurate to think that a CLI language performs better or better than other CLI languages in CTS ing to the underlying CTS. On the contrary, each different CLI language represents a different understanding of the CTS underlying object model, which you will see more clearly in the next section.

  CLI details

When designing a CLI language, the second problem that must be considered is to integrate the underlying CLI execution mode into the detailed level of the language. What problems does this language solve? Is there any necessary tool for this language to solve these problems? What program developers may be attracted by this language?

For example, the value type exists on the managed stack. In many cases, the value type can see its own existence.

1. Through implicit binning, when a value type instance is assigned to an object or when a virtual method is called through a value type;

2. When this value type is used as a member of the application reference class type;

3. When the value type is treated as a CLI array member;

It should be noted that, in this case, whether the developer is allowed to operate on the Value Type address is a problem that must be considered during the CLI language design.
Problems

When the spam collector scan is tightening, any objects on the managed Stack are very likely to face the issue of locating. Pointers to objects can be tracked and modified in real time. Developers cannot manually track the data by themselves. Therefore, if you obtain an address that may be on the managed stack, you need a pointer in the tracking form in addition to a local pointer.

What do sellers consider? That is, it requires simplicity and security. directly providing pointers that track an object or set in a language complicate the language. Without such support, the complexity will be reduced, the number of available and potential program developers may increase. In addition, allowing program developers to operate on short-lived value types increases the possibility of errors, program developers may intentionally or unintentionally perform error operations on the memory, and do not support tracking pointers. A potentially safer real-time environment is generated.

On the other hand, efficiency and flexibility must also be considered. Each time a value type is assigned to the same object, a new value binning operation occurs, the allowed access binning Value Type allows updates in the memory, which may produce a huge performance improvement. You cannot use the pointer algorithm to re-declare a CLI array without the trace form pointer. This means that the CLI array cannot be re-declared using the standard template library or a general algorithm. Allow operation of the binning value to make the design more flexible.

In C ++/CLI, Microsoft selects the address set mode to process the value types on the hosting stack.

int ival = 1024;
int^ boxedi = ival;
array<int>^ ia = gcnew array<int>{1,1,2,3,5,8};
interior_ptr<int> begin = &ia[0];

value struct smallInt { int m_ival; ... } si;
pin_ptr<int> ppi = &si.m_ival;

Typically, C ++/CLI developers are complex system programmers who are responsible for providing lower-layer internal structures and organized applications. These are precisely the foundation of future business development. C ++/CLI developers must take into account the testability and enforceability, so they must look at the underlying CLI structure at a high level of the system. The level of CLI details reflects the developers' faces.

Complexity itself does not mean a denial of quality. Humans are much more complicated than single-cell bacteria. This is certainly not a bad thing. However, when expressing a simple concept becomes more complicated, this is often considered a bad thing. In C ++/CLI, the CLI development team has tried to provide a sophisticated way to express a complex thing.

  Additional features

The third design aspect is the specific functional language layer, which far exceeds the direct support provided by CLI, although this may require a ing between the language Layer Support and the CLI underlying execution mode. However, in some cases, this is precisely impossible because the language cannot regulate CLI behavior. In this case, the virtual function is defined in the construction and destructor of the base class. According to the linguistics of ISO-C ++ in this case, it is impossible to reset the virtual table with the construction and fictitious functions of each base class, because the virtual table handle is managed in real time, instead of a language.

Therefore, this design is a compromise between perfection and feasibility. The additional functions provided by C ++/CLI are mainly manifested in three aspects:

1. One way to obtain resources is to initialize the reference type. In addition, an automated tool is provided, this object is used for garbage collection objects that consume less resources and are declared deterministic and automatically extinct.

2. the syntax of a deep copy form is the same as that of the C ++ copy constructor and the copy assignment operator, but it is not applicable to the value type.

3. In addition to the initial general CLI mechanism, C ++ templates of the CTS type are also directly supported. These are the topics discussed in my first article. In addition, the STL version can be verified for the CLI type.

Let's look at a simple example, a deterministic extinction problem. Before the Garbage Collector re-declares a memory associated with the object, a related method will be called if it exists. You can think of this method as a super destructor because it has nothing to do with the life cycle of the object program. This is called the end. Whether or not the final function is called and when it is called are not clearly specified. This is the uncertain termination of the garbage collector.

In the case of dynamic memory management, non-deterministic termination work is very good. When the available memory becomes less and less available, the garbage collector is involved and starts to solve the problem. However, when an object maintains an important resource, such as a database connection, locking in certain categories, or possibly local heap memory, it may also have a poor performance. In this case, resources should be released immediately as long as they are not needed. Currently, the solution supported by CLI is to release resources by executing the Dispose method provided by the IDisposable interface for a class. The problem here is that the execution of the Dispose method requires a clear declaration, so it cannot be called.

The most basic design mode in C ++ is to obtain resources through initialization. This means that classes Use constructors to obtain resources. On the contrary, classes

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.