您的位置:首页 > 编程语言 > C#

managed and unmanaged code in c#

2010-12-21 11:29 316 查看
在看Unity plugin的时候,看到managed和unmanaged code,根据我所看的内容上下文,基本猜出来时啥意思。不过当时也就不求甚解那么过了。昨天看.net dll的一些内容的时候,重新看到了这个概念,于是google了一把。在一个论坛里面找到了一个比较全面科学的解释。

"Unmanaged code" is a new name for an
old concept. Unmanaged code stands for native machine code. Software is
typically written in some high-level language such as Pascal, C or C++.
These languages are translated into machine code (aka unmanaged code) by
the compiler and its companion tools (assembler, linker, librarian,
etc). The generated code runs natively on the host processor; that is,
the processor directly executes the code generated by the compiler. This
approach typically results in fastest code execution, but diagnosing
and recovery from errors might be easier in managed code.

Managed
code is a new name, but the concept also is pretty old. Today, "managed
code" typically stands for the system used by Microsoft .NET, but .NET
is just one example of a managed code system. The .NET system takes
source code in any of the supported languages (which include C, C++, C#,
Pascal, and many others), and translates it into code designed for a
virtual machine. The real processor cannot execute this code natively,
but it can execute a program which then in turn executes the virtual
machine's codes. The program that executes the virtual machine code is
known as the virtual machine. While potentially slower than native code
execution, the virtual machine can manage code (!) better than real
machines. For example, the virtual machine can supervise memory
allocation, automatically handle disposal of unused memory, and provide
many other services that a native (unmanaged) application typically must
explicitly provide. If the virtual machine does its job correctly, all
applications using this virtual machine are likely to benefit.

概念都是很老的,只不过两个新名词,类似pure java和jni。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: