[C ++/CLI Programming Guide] [7] basic concepts

Source: Internet
Author: User

The following describes some basic concepts:

1) Dynamic Link Library/assemblyProgramSet: dynamic link library. We know in ISOC ++ that files suffixed with. dll are dynamic link libraries.CodeBut after CLI extension, the corresponding managed components are called Assembly assembly. An assembly is the construction block of A. Net Framework application. An assembly constitutes the basic unit of deployment, version control, reuse, activation range control, and security permissions. An assembly is a set of types and resources generated for collaborative work. These types and resources constitute a logical functional unit. The Assembly provides the Common Language Runtime library with the information required to understand the type implementation. For the Runtime Library, the type does not exist outside the Assembly context.

An assembly consists of Assembly metadata, type metadata, intermediate language code, and resources. For example:

An assembly is divided into a private assembly and a shared assembly. Private assembly is used at the application level, and shared assembly is public to the whole system.

2) Il intermediate language: IL = intermediate language. Il intermediate language is the basis of CLI, all. netSource code(Written in any language) is compiled into Il. When the software is installed, Il is converted to machine code, or processed by the just-in-time, JIT compiler at runtime. C ++/CLI is an extension of. net, so c ++/CLI is compiled as Il code.

3) stack/local Heap/managed heap: in fact, the concept of stack is available in ISOC ++. The stack, which we mentioned previously, is automatically allocated and released by the compiler, it is used to store function parameter values, return addresses of functions, and non-static local variable values. The operation method is similar to the stack in the data structure (first-in-first-out LIFO ). The heap is usually distributed and released by programmers. If the programmer does not release the heap, the program may be recycled by the OS when it ends. After C ++/CLI extends the CLI. the common language of net provides the Garbage Collector for automatic management of the heap. Therefore, in the past, the heap in ISOC ++ had to be divided into local heap and managed heap, the local heap refers to the memory allocated in the previous ISOC ++. The memory is allocated and released by the programmer. The other is that the memory is allocated by the programmer.. Net garbage collector.

4) Local type/Local Code: the local type is the type in ISOC ++. This type is allocated to the stack and local stack. Local Code is called local code.

5) managed type/managed code: In C ++/CLI, the managed type is introduced, and the Code implemented by the managed type is managed code.

6) value type/Ref reference type: managed types are classified into value type and ref reference type. The value type is assigned to the stack, the reference type is assigned to the managed stack, and the managed stack is automatically managed by the. NET garbage collector.

7) Reference/pointer/handle tracing handle: In ISOC ++, we know the concepts of reference and pointer, such as defining int I = 10; referencing and defining Int & IR = I; and pointer definition int * Pi = & I; In C ++/CLI, we can also allocate memory for it, such as system: String ^ STR = gcnew system :: string ("hello"), but the memory is.. Net garbage collector, so the objects created by gcnew managed by the garbage collector are called handle tracking handles.

8) Property: In the managed type, we can use the property to encapsulate the field (member variable), like the getx () and setx () Methods of the previous variables.

9) delegate delegation: In the hosting world, a new type of delegate delegation is introduced. delegate is actually our previous definition of ISOC ++ function pointer, which is used to implement the callback mechanism.

10) Events event: You can define event members in the managed type. An event is actually an instance of delegate.

11) gcnew (constructor)/delete (~ Destructor)/finalizer (! Termination function): If a programmer wants to create a managed object, gcnew will be used for hosting the stack. The objects created by gcnew are called handle tracing handles, the process of calling gcnew actually involves calling the allocated memory and constructor. When handle ends, we can call Delete to call the destructor, indicating that the object is no longer used, so that the next round of garbage collection can recycle the object, however, it does not matter if we do not call the destructor. net will call the termination function and start to recycle the object when it detects that the object is no longer in use.

12) attribute feature: the attribute class associates predefined system information or user-defined custom information with the target element. The target element can be an assembly, class, constructor, Delegate, enumeration, event, field, interface, method, executable file module, parameter, property), return value, structure, or other attributes ). The information provided by an attribute is also called metadata. Metadata can be checked by the application at runtime to control the way the program processes data, or by external tools before running to control the way the application processes or maintains itself. For example, if. NET Framework predefines the property type and uses the property type to control runtime behaviorProgramming LanguageThe property type is used to indicate the language functions that are not directly supported by the. NET Framework Public type system.

13) Reflection reflection: The underlying layer of C ++/CLI is Il, which leads to the strong self-describing ability of DLL and exe produced by C ++/CLI compilation, if no source code is available, you can obtain it at runtime. net, including methods, attributes, events, and constructor. You can also obtain
Member name, qualifier, and parameters. With reflection, you can be familiar with every type. If you obtain information about the constructor, you can directly create an object, even if the object type is unknown during compilation.

    Complete!

    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.