编程中托管或非托管代码是什么? [英] What is managed or unmanaged code in programming?

查看:263
本文介绍了编程中托管或非托管代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#代码中使用了特定的命令,效果很好。但是,据说在非托管代码中行为不当。

I am using a specific command in in my C# code, which works well. However, it is said to misbehave in "unmanaged" code.

什么是托管或非托管代码?

What is managed or unmanaged code?

推荐答案

以下是MSDN上有关非托管代码的一些文本

Here is some text from MSDN about unmanaged code.


某些库代码需要调用非托管代码(例如,本机代码API,例如Win32)。因为这意味着超出托管代码的安全范围,所以需要格外小心。

Some library code needs to call into unmanaged code (for example, native code APIs, such as Win32). Because this means going outside the security perimeter for managed code, due caution is required.

以下是托管代码的其他补充说明:

Here is some other complimentary explication about Managed code:


  • 由CLR执行的代码。

  • 以公共语言运行时为目标的代码.NET Framework的基础,即托管代码。

  • 托管代码提供了CLR提供诸如内存管理,跨语言集成,代码访问安全性,以及对象的自动寿命控制。所有基于IL的代码都作为托管代码执行。

  • 在CLI执行环境下执行的代码。

  • Code that is executed by the CLR.
  • Code that targets the common language runtime, the foundation of the .NET Framework, is known as managed code.
  • Managed code supplies the metadata necessary for the CLR to provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on IL executes as managed code.
  • Code that executes under the CLI execution environment.

对于您的问题:

我认为这是因为NUnit执行用于UnitTesting的代码,并且其中的某些部分不受管理。但是我不确定,所以不要拿它当黄金。我相信有人可以为您提供更多信息。希望对您有所帮助!

I think it's because NUnit execute your code for UnitTesting and might have some part of it that is unmanaged. But I am not sure about it, so do not take this for gold. I am sure someone will be able to give you more information about it. Hope it helps!

这篇关于编程中托管或非托管代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆