gpt4 book ai didi

computer-science - 托管代码与非托管代码

转载 作者:行者123 更新时间:2023-12-04 14:41:18 27 4
gpt4 key购买 nike

我试图让我的思想围绕托管与非托管代码的概念。如果我错了,请纠正我,但托管代码是任何可以编译为字节码的东西,而非托管代码则可以编译为机器代码。

这样对吗?

最佳答案

来自 annakata 的回答:

Managed code is not compiled to machine code but to an intermediate language which is interpreted and executed by some service on a machine and is therefore operating within a (hopefully!) secure framework which handles dangerous things like memory and threads for you. In modern usage this frequently means .NET but does not have to.

Unmanaged code is compiled to machine code and therefore executed by the OS directly. It therefore has the ability to do damaging/powerful things Managed code does not. This is how everything used to work, so typically it's associated with old stuff like .dlls



现在,引擎盖下发生了什么?
托管与非托管是 关于内存 .

在托管代码中,代码本身并不直接操作内存。它向代表代码执行此操作的运行时提供指令。这样,可以阻止不安全或非法的操作,并且代码在半沙箱中运行。托管语言可以而且经常确实有非托管代码——这就是计算的本质。

把内存想象成一个巨大的 parking 场。托管语言和非托管语言的区别是这样的:

用一种管理语言,您走到代客泊车处并解释说您想要停放 10 辆车。您不知道它们究竟停在哪里,但您知道代客泊车随时乐意为您取回它们。您也无法决定它们的停放位置 - 您只需告诉代客他们需要停放即可。

在不受管理的语言中,您的工作是挑选位置。您可以驶入其他汽车,将车停在残疾人车位,等等 - 这可以为您提供更好的性能(您不必不断向代客传达指令),但您也可能犯很多愚蠢/危险的错误。

关于computer-science - 托管代码与非托管代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38404743/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com