O 'Reilly-. NET Framework essentials, 2nd Edition-Chapter 2 (continued)

Source: Internet
Author: User
2.6.1.4 class, properties, indexers
See detail in the next chapter
2.6.1.5 Interfaces
Interfaces support exactly the same concept as a C ++ abstract base class (ABC) with only prure virtual functions. an ABC is a class that declares one or more pure functions and thus cannot be instantiated. you specify them, but you don't implement them. A class that derives from you interface must implement you interface. an interface may contain in methods, properties, indexers, and events. in. net, a class can derive from multiple interfaces.

2.6.1.6 delegates
DeleGate A declaration is used to define a reference type, which can be used to encapsulate a method with a specific signature. The delegated instance can encapsulate static methods or instance methods. Delegation is roughly similar to C ++ function pointer in ; however, delegation is safe and reliable. .
2.6.2 the common language specification (CLS)
The CLs specifies a series of basic rules that are required for language integration. since MS provides the CLS that spells out the minimum requirements for being. net Language, compiler vendors can build their compilers to the specification and provide versions that target. net. besides compilers writers, application developers shoshould read The CLs and use its rules to guarantee interoperation.

CLSIs a standard, if you want to write your own. NetCompiler or development-relatedProgramTo comply with this standard. Because this standard defines that different languages are compiled. NetBasic Language specifications.

2.7 CLR execution

The major component of the CLR include the class loader, verifier, JIT compilers, and other execution support, such as code management, security management, garbage collection, exception management, debug management, stored aling management, thread management, and so on.

2.7.1 Class Loader
The Class Loader Loads. net classes into memory and prepares them for execution. before it can successfully do this, it must locate the target class. to find the target class, the Class Loader looks in several different places, including the application configuration file (. Config ) In the current directory, the GAC, and the metadata that is part of the PE file, specially the manifest. the information that is provided by one or more of these items is crucial to locating the correct target class. recall that a class can be scoped to a particle namespace, a namespace can be scoped to a particle assembly, and an assembly can be scoped to a specific version. given this, two classes, both named car, are treated as different types even if the version information of their assemblies are the same.
Class LoaderLoad classes to the memory and prepare them for execution. Before doing this, the Class Loader must first discover the target class. To find the target class, the Class Loader looks for it in several different places, including the application configuration file in the current directory,GAC,PEFile metadata, especially the Declaration Part. The information found in one or more of these duplicates is very important for successfully loading the target class. A call can occur when a class is called in a namespace, a namespace is called in a component, and a component is called in a specified version. Under this condition, both classes are called "cars" and will be considered as different types, even if their component version information is the same.

Function of the Class Loader:
Once the class loader has found and loaded the target class, it caches the types information for the class so that in doesn't have to load the class again for the duration of this process. by caching this information, it will later determine how much memory is needed to allocate for the newly created instance of this class. once the target class is loaded, the Class Loader injects a small stub, like a function Prolog, into every single method of the loaded class. this stub is used for two purposes: to denote the status of JIT compilation and to transition between managed and unmanaged code. at this point, if the loaded class references other classes, the class loader will also try to load the referenced types. however, if the referenced types have already been loaded, the class loader has to do nothing. finally, the Class Loader uses the appropriate metadata to initialize the static variables and instantiate an object of the loaded class for you.

2.7.2 verifier.
What is? Is the component that executes at runtime to verify that the code is type safe.
When verify? After the class loader has loaded a class and before a piece of IL code can execute.
What verify?
Main: the metadata is well formed; the Il code is type safe.
Other: Performs rudimentary control-flow analysis of the Code to ensure that the Code is using types correctly.

Note: 1 it kicks in only when a method is being invoked, not when a class or assembly is loaded.
2 verification is an optional step because trusted code will never be verified but will be immediately directed to the JIT compiler for compilation.

2.7.3 JIT compilers.
what is it? Just In Time compiler
what function? Convert Il to (managed) native code so that it can execute on the target operation system.
How perform? JIT compilation occurs only the first time a method is invoked. recall that the class loader adds a stub each method during class loading. at the first method invocation, the VES reads the information in this stub, which tells it that the code for the method has not been jit-compiled. at this indication, the JIT compiler complies the method and injects the address of the managed native method into this stub. during subsequent invocations to the same methods, no JIT compilation is needed because each time the VES goes to read information in the stub, is sees the address of the native method. because the JIT compiler only performs its magic the first time a method is invoked, the methods you don't need at runtime will never be jit-complied.

Other: If you want to avoid the cost of JIT compilation at runtime, you can use a special tool calledNgen, Which compilers your il during installation and setup time.

2.7.4Execution Support and Management
1 garbage collection
2 Exception Handling
3 Security Support: code is safe to execute, declarative and imperative security checks.
4 debug support: controlling program execution, breakpoints, exceptions, control flow...
5 interoperation support: managed (CLR) and unmanaged (no CLR) worlds

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.