c# - 什么是编程中的托管代码或非托管代码?

标签 c# .net unmanaged definition managed

我在我的 C# 代码中使用了一个特定的命令,它运行良好。但是,据说它在“非托管”代码中行为不端。

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

最佳答案

This是一篇关于该主题的好文章。

总而言之,

  1. 托管代码 未编译为机器代码,而是编译为由机器上的某些服务解释和执行的中间语言,因此在(希望如此!)处理危险事物的安全框架内运行像你的内存和线程。在现代用法中,这通常表示 .NET,但并非必须如此。

An application program that is executed within a runtime engine installed in the same machine. The application cannot run without it. The runtime environment provides the general library of software routines that the program uses and typically performs memory management. It may also provide just-in-time (JIT) conversion from source code to executable code or from an intermediate language to executable code. Java, Visual Basic and .NET's Common Language Runtime (CLR) are examples of runtime engines. (Read more)

  1. 非托管代码 被编译为机器代码,因此由操作系统直接执行。因此,它有能力做托管代码做不到的破坏性/强大的事情。这就是一切过去的工作方式,因此通常它与 .dll 等旧内容相关联。

An executable program that runs by itself. Launched from the operating system, the program calls upon and uses the software routines in the operating system, but does not require another software system to be used. Assembly language programs that have been assembled into machine language and C/C++ programs compiled into machine language for a particular platform are examples of unmanaged code.(Read more)

  1. native 代码通常是非托管的同义词,但并不完全相同。

关于c# - 什么是编程中的托管代码或非托管代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/334326/

相关文章:

使用 Onclientclick 或 Onsubmit 都不会调用 JavaScript 函数

c# - 如何在 ASP.NET 中编辑、更新和删除 GridView 中的行

c# - 如何在 PHP 和 ASP.net 应用程序之间共享 session ?

.Net4, Monitor.Enter(lockObject, acquiredLock)

c# - 使用 DllImport 将非托管 dll 加载到托管应用程序中

dll - 在 nuget 包中添加构建后事件

c# - 如何通过缓存键锁定?

c# - 我们什么时候需要将 ProcessStartInfo.UseShellExecute 设置为 True?

c# - ASP.Net Async MVC Controller 功能导致 Razor View Engine 错误

.net - 将 C# 字符串传递给非托管 C++ DLL