散焉者

出自庄子

导航

学习inside csharp第二天

Posted on 2004-12-10 20:44  king2true  阅读(142)  评论(0)    收藏  举报

果然是站在一定高度啊,而且有一定深度!
先是介绍了一下win32中的PE,也就是把源代码程序变成二进制的可执行文件。需要运行的时候,操作系统
就把这些二进制放到内存中来,然后找到所需的数据地址。
接着,说.net中的MSIL。在.net中有两个最重要性质:
all .NET languages have access to the same .NET functionality
and that code written in these various languages can interoperate seamlessly.
第一是:所有的.net中的语言都可以访问相同的.net功能性
第二是:这些用不同语言写的代码可以毫无障碍的互相调用运行(英语水平有限,不知翻译得对不?)
要达到这样的目标,就要靠MSIL。源程序通过.net编译器产生MSIL输出,代替Windows PE。
通过ILASM我们还可以直接用MSIL的操作码写程序,并且在附件中列出了MSIL的操作码。
我不知道有没有必要用MSIL写代码,挺麻烦的,这是干吗呢!?
然后我就如同堕入十八层地狱般的痛苦,一个.net程序的编译和执行过程的抽象描述,简直要了我的命。
一个字——晕!
就算再晕也要继续阿!擦干带着泪水的眼屎!继续!。。。。。
执行一个.net程序的过程是:
1 A programmer writes source code using any .NET language.
  一、一个程序员用任何.net的语言写好源程序。/*我真希望是电脑自动完成啊!*/
2 The source code is then compiled into what appears to be a standard PE file.
  二、然后源程序被编译成象是一个标准的PE的文件。/*我都不知道在说啥!*/
3 The .NET compiler outputs the MSIL code and a manifest into a read-only part of the EXE
that has a standard PE header. (I'll get into exactly what a manifest is in the next
section. For now, it's enough to understand that the term manifest refers to the
information stored in a .NET binary that describes that binary's contents and runtime
requirements.)
  三、.net编译器产生MSIL代码和一个manifest/*根据字典解释应该是a list of passengers的意思*/
       并把它们放入有一个标准PE头的EXE文件的只读部分里。/*晕了·晕了*/
       (现在我们只要知道这个manifest是引用储存在.net二进制里的信息,用来描述二进制的内容和
        运行环境的)
4 So far, so good. However, here's the important part: when the compiler creates the output,
it also imports a function named _CorExeMain from the .NET runtime.
  四、到目前为止,一切都好。/*那里有头疼药?我有点晕!*/这里是最重要的部分:但这个编译器编译时,它同时还
      从.net运行中输出一个叫做_CorExeMain的过程。
5 When the user runs the application, the operating system loads the PE as well as any
dependent DLLs, such as the one that exports the _CorExeMain function (mscoree.dll),
just as it does with any valid PE.
  五、当用户运行这个程序的时候,操作系统装载PE和与之相关的动态链接库(DLL)。其中就有
      _CorExeMain程序输出mscoree.dll。 正象它处理任何有效的PE一样。
6 The operating system loader then jumps to the entry point inside the PE, which is put
there by the .NET compiler. Once again, this process is exactly how any other PE is executed in
Windows
  六、操作系统载入被.net编译器放入PE中的程序入口,这次又和其他任何PE在windows里执行的情况一样。
7 Because the operating system obviously can't execute the MSIL code, the entry point is just a
small stub that jumps to the _CorExeMain function in mscoree.dll.
  七、由于操作系统显然不能执行MSIL代码,所以程序入口只是一个小小的抽头,然后跳到mscoree.dll中的
       _CorExeMain 程序。
8 The _CorExeMain function starts the execution of the MSIL code that the compiler placed in
the PE.
  八、_CorExeMain程序开始这个PE中的MSIL代码的执行。
9 MSIL code can't be executed directly because it's not in a machine-executable format.
Therefore, the common language runtime compiles the MSIL—by using a just-in-time compiler
(or JITter)—into native CPU instructions as it processes the MSIL. JIT compiling occurs only
as methods in the program are called. The compiled executable code is cached on the machine and
recompiled only if there's some change to the source code.
  九、MSIL代码不可以直接执行,因为它不是可执行的机器格式。因此,通过使用just-in-time(或者JITter)
编译器将它编译成可执行的本地CPU指令,作为MSIL的执行过程。当调用程序中的方法的时候,JIT编译才开始
编译。被编译的可执行代码被隐藏在机器里,而且只有在源程序发生改变时,他才重新编译。
~~~~~~~~~~~~~:-( 天啊!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

简直是经典!特别是最后一段,杀人不见血!
完全不知道在说什么?我英文水平太低,还是理解有问题。但是我完全不知道那句jIT compiling occurs
only as methods in the program are called。是啥东西?那个program?methods?
请教高人后,终于明白原来MISL中也有对象的!唉!真是啥啊!这回是我傻。

不知道翻译的对不??

###############################################################