本机代码和托管代码之间的区别?

发布于 2024-07-21 00:26:32 字数 138 浏览 3 评论 0原文

例如,当查看 GlowCode profiler 网站时,它显示:

GlowCode 6.2 和 x64 配置本机、托管和混合 C++、C#、.NET 代码

它们是什么意思?

For example, when looking at the GlowCode profiler website it says:

GlowCode 6.2 and x64 profile native, managed, and mixed C++, C#, .NET code

What do they mean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坏尐絯 2024-07-28 00:26:32

本机代码是内存不是“托管”的代码,例如,内存不会为您释放(例如,C++ 的删除和 C 的释放),没有引用计数,没有垃圾收集。 您猜对了,托管代码是内存空闲并为您分配、垃圾收集和其他好处的代码。

混合代码是指您拥有调用非托管层的托管代码。 通常,当您有一个纯非托管 C++ DLL 并使用 P/invoke 从 .NET 调用它时。

Native code is the code whose memory is not "managed", as in, memory isn't freed for you (C++' delete and C's free, for instance), no reference counting, no garbage collection. Managed code, you guessed it, is the code whose memory is free and allocated for you, garbage collection and other goodies.

Mixed code is when you have managed code that calls onto an unmanaged layer. Normally, when you have a pure unmanaged C++ DLL and you call it from .NET using P/invoke.

吲‖鸣 2024-07-28 00:26:32

本机代码经过编译可直接与操作系统一起使用。 然而,托管代码是预编译的(Java 中的字节码),但随后由即时编译器在运行时处理为本机代码。 托管代码有一个有趣的副作用,即可以在不同的操作系统上运行,因为机器代码是在虚拟机实际使用它之前才创建的。 这样,您就可以在 Windows 上运行 .NET 应用程序,也可以在安装了 Mono 运行时的 Linux 或 Mac 上运行它们。 目前的可移植性并不像Java那么干净(因为微软天生的封闭架构),但这个概念仍然存在。

如果您正在运行非托管应用程序,则代码已编译为针对指定操作系统/硬件运行。 任何对其他操作系统/指令集的可移植性都会丢失,必须重新编译才能执行。

Native code is compiled to work directly with the OS. Managed code however, is precompiled (bytecode in Java-speak) but is then processed by the Just In Time Compiler to native code at runtime. Managed code has the interesting side effect of having the potential of running on different operating systems, because the machine code is not created until the VM actually uses it. This way, you are able to run .NET apps on Windows and also run them on Linux or Mac that have the Mono runtime installed. The portability is not as clean currently as Java is (because of Microsoft's naturally closed architecture), but the concept remains.

If you are running an unmanaged app, the code has been compiled to run for the designated OS/Hardware. Any portability to another OS/instruction set is lost and must be recompiled to execute.

所有深爱都是秘密 2024-07-28 00:26:32

本机代码是用其运行的计算机的“本机”机器语言编写的,并直接由处理器执行。

托管代码是用特殊语言编写的,需要另一个程序来运行(即管理)它。 这个其他程序通常称为解释器,因为它解释特殊语言。

C 和 C++ 程序是本机的。

Java 和 C#(以及与此相关的所有 .NET 语言)都是受管理的。

托管 C++ 是一种特殊形式的 C++,在 .NET 解释器中运行。

混合程序是使用本机代码和托管代码的程序。

Native code is written in the "native" machine language of the computer that it is running on and is executed directly by the processor.

Managed code is written in a special language that requires another program to run (i.e. manage) it. This other program is often called an interpreter as it interprets the special language.

C and C++ programs are native.

Java and C# (and all .NET languages for that matter) are managed.

Managed C++ is a special form of C++ that runs in the .NET interpreter.

A mixed program is a program that uses code that is both native and managed.

携君以终年 2024-07-28 00:26:32

在公共语言运行时 (CLR) 控制下运行的代码称为托管代码。 不在 CLR 下运行的代码称为本机代码。

Code that runs under the control of the common language runtime (CLR) is known as managed code. Code that does not run under the CLR is known as native code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文