What is managed code?

原创 2007年09月14日 15:16:00
What is managed code?
Recently I have been working on pulling together some background information and I thought I'd share it here.  I certainly don't claim any of this is news, but at least google will help me find it next time I need it ;-)
What is managed code?
Managed code is code that has its execution managed by the .NET Framework Common Language Runtime. It refers to a contract of cooperation between natively executing code and the runtime. This contract specifies that at any point of execution, the runtime may stop an executing CPU and retrieve information specific to the current CPU instruction address. Information that must be query-able generally pertains to runtime state, such as register or stack memory contents.
The necessary information is encoded in an Intermediate Language (IL) and associated metadata, or symbolic information that describes all of the entry points and the constructs exposed in the IL (e.g., methods, properties) and their characteristics. The Common Language Infrastructure (CLI) Standard (which the CLR is the primary commercial implementation) describes how the information is to be encoded, and programming languages that target the runtime emit the correct encoding. All a developer has to know is that any of the languages that target the runtime produce managed code emitted as PE files that contain IL and metadata. And there are many such languages to choose from, since there are nearly 20 different languages provided by third parties – everything from COBOL to Camel – in addition to C#, J#, VB .Net, Jscript .Net, and C++ from Microsoft.
Before the code is run, the IL is compiled into native executable code. And, since this compilation happens by the managed execution environment (or, more correctly, by a runtime-aware compiler that knows how to target the managed execution environment), the managed execution environment can make guarantees about what the code is going to do. It can insert traps and appropriate garbage collection hooks, exception handling, type safety, array bounds and index checking, and so forth. For example, such a compiler makes sure to lay out stack frames and everything just right so that the garbage collector can run in the background on a separate thread, constantly walking the active call stack, finding all the roots, chasing down all the live objects. In addition because the IL has a notion of type safety the execution engine will maintain the guarantee of type safety eliminating a whole class of programming mistakes that often lead to security holes.
Contrast this to the unmanaged world: 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 forth, but the system doesn’t actually know what the application is doing. Therefore, it can’t make any guarantees about what happens when the application runs.


携程网被黑,备份很重好 (1)数据库备份:直接拷贝data文件是不好的,因为mysql服务器可能在运行和操作数据库。备份还原还有:mysqlhotcopy工具。 ./bin/mysqldump -u...
  • hxchuan000
  • hxchuan000
  • 2015年07月03日 16:08
  • 697


  • ckao7470
  • ckao7470
  • 2014年06月29日 00:38
  • 3788


// sometimes I believe compiler ignores all my comments Exception up = new Exception(“Something is...
  • river_like
  • river_like
  • 2014年01月14日 10:45
  • 1484

Spark修炼之道(高级篇)——Spark源码阅读:第八节 Task执行

  • lovehuangjiaju
  • lovehuangjiaju
  • 2015年10月29日 12:00
  • 4639


原址:http://hualang.iteye.com/category/143855 public class  Handler extends Object   java.lang.O...
  • luckypeng
  • luckypeng
  • 2015年07月30日 19:38
  • 333

jdbc14 及 jdbc16 共存所带来的问题【未完待续】

  • scottsiu
  • scottsiu
  • 2014年06月17日 13:49
  • 3725

CVPR2013一些论文集合供下载(visual tracking相关)

CVPR2013一些论文集合供下载(visual tracking相关) zouxy09@qq.com http://blog.csdn.net/zouxy09          看到CVPR...
  • zouxy09
  • zouxy09
  • 2013年04月26日 21:18
  • 20576


"初探列存储数据库"   fujohnwang 转自:http://afoo.me/col-store.html 1 - 基于行存储的RDBMS行为分析2 - 基于列存储的RDBMS行...
  • chenyechao
  • chenyechao
  • 2014年01月23日 12:34
  • 617

Android aapt使用方法

D:>aapt -h  ERROR: Unknown command ‘-h’  Android Asset Packaging Tool Usage:  aapt l[ist] [-v]...
  • kaka735
  • kaka735
  • 2015年05月26日 10:15
  • 553


21.Junit 设置默认的jvm参数方法问题:我们的工程中运行junit时,要为每个testcase设置一下jvm的参数,并且jvm的参数都是要一样的?有没有方法设置所有testcase的jvm参数...
  • FansUnion
  • FansUnion
  • 2016年06月04日 11:26
  • 2139
您举报文章:What is managed code?