前段时间小弟复习的时候,抄录了一些自认为对认识Managed code有好处的一些句子。现帖在这里,希望能对有需要的朋友有所帮助。这些抄录主要是针对Managed Code的定义以及Managed Code和Unmanaged Code的优缺点,同时也提到了其在CLR中是如何工作的。
事先声明:这些抄录(定义)主要出自以下书籍(文章)
1. Programming in .NET Environment
2. Shared Source CLI
3. Essential .NET
4. 老师的讲义 (By David Gray & Rob Miles)
5. Internet(Google.com)
再次声明,这是抄录,只是用于大家学习交流,如果你要用到其中的原文,请注明出处,谢谢。
² Virtual execution in the CLI occurs under the control of its execution engine, which hosts components (as well as code that is not component base) by interpreting the metadata that describes them at runtime. Code that runs in this way is often referred to as managed code.
² Managed code is code that has its execution managed by the .NET Framework CLR.
² When we talk about ‘managed code’, we are talking about a ‘virtual execution environment’. By this we mean that the environment in which our programs runs is artificial, and removed from the underlying hardware. The environment takes the form of a program which plays the role of the supporting computer.
² Any of the languages that target the runtime produce managed code emitted as PE files that contains IL and metadata. Before the code is run, the IL is compiled into native executable code. And since this compilation happens by the managed execution environment, the managed execution environment can make guarantees about what the code is going to do.
² Managed application written to take advantage of the features of the CLR perform more efficiently and safely, and take better advantage of developer’s expertise in languages that support the .NET Framework.
² Managed code runs completely inside the .Net Framework, without relying on other resources such as COM components. The CLR translates managed code to executable code, which the CPU then executes.
² Unmanaged executable files are basically a binary image, x86 code, loaded into memory. The program counter gets put there and that’s the last the OS knows. There are protections in place around memory management and port I/O and so on, but the system doesn’t actually know what the application is doing. Therefore, it cannot make any guarantees about what happens when the application runs.
² Unmanaged code does not run inside the .NET environment, therefore, it cannot make use of any .NET managed facilities.