• O'Reilly .NET Framework Essentials, 2nd Edition第二章(续)


    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 methods, properties, indexers, and events. In .NET, a class can derive from multiple interfaces.


    2.6.1.6 Delegates
    Delegate
    声明用于定义一种引用类型,该类型可用于将方法用特定的签名封装。委托实例可以封装静态方法或实例方法。委托大致类似C++中的函数指针;但是委托是类型安全和可靠的
    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 a .NET language, compiler vendors can build their compilers to the specification and provide languages that target .NET. Besides compilers writers, application developers should read the CLS and use its rules to guarantee interoperation.

    CLS是一个标准,若要写自己的.NET编译器,或者开发相关程序,需要遵循这个标准。因为这个标准定义了不同语言被编译成.NET语言的基本规范


    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, marshaling 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 particular namespace, a namespace can be scoped to a particular 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.
    类加载器把类加载到内存,并让它们执行的准备。在完成这个之前,类加载器必须先发现目标类。为了发现目标类,类加载器在几个不同的地方进行查找,包括在当前目录下的应用程序配置文件,GACPE文件中的元数据,特别是声明部分。在这些的一个或者多个重中找到的信息对成功加载目标类是非常重要的。调用能发生在下面的情况下:在一个命名空间中调用一个类,在一个组件中调用一个命名空间,在一个确定的版本中调用一个组件。在这种条件下,两个类都叫“汽车”,将被看作不同的类型,即使它们组件的版本信息是一样的。

    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 called ngen, which compilers your IL during installation and setup time.

    2.7.4 Execution 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
  • 相关阅读:
    python之各种包
    正则表达式
    import/模块的导入
    迭代器/可迭代对象/生成器
    Day2 列表list
    Day1 字符串格式化
    Day1 字符编码及编码函数
    Python 学习笔记 之 随着学习不断更新的Python特性搜集
    Day1 input&print
    Newtonsoft.Json日期转换
  • 原文地址:https://www.cnblogs.com/yang_sy/p/1087939.html
Copyright © 2020-2023  润新知