如果未解释C#,那么为什么需要VM? [英] If C# is not interpreted, then why is a VM needed?

查看:62
本文介绍了如果未解释C#,那么为什么需要VM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关C#的争议,有些人说它是解释性的,有些人说不是.我确实知道它已被编译为MSIL,然后在运行时进行了JIT处理,具体取决于处理器等.但是,它不是仍以需要VM(.NET)来运行的方式来解释吗?

I have read a lot of controversy about C#, where some say it's interpreted, some say it's not. I do know it's compiled into the MSIL and then JITed when run, depending on the processor etc...but isn't it still interpreted in the way it needs a VM (.NET) to run?

推荐答案

VM只是微处理器的抽象.它只是一个定义,并不真正存在.IE.您无法在VM上运行代码;但是,您可以为其生成IL代码.优点是语言编译器不需要了解有关各种实际处理器的详细信息.由于不同的.NET语言(例如C#或VB(以及更多))会产生IL,因此它们在此级别上是兼容的.例如,这与其他约定(例如通用类型系统)一起,使您可以使用从C#程序中的VB代码生成的DLL.

The VM is just an abstraction of a microprocessor. It is just a definition and does not really exist. I.e. you cannot run code on the VM; however, you can generate IL code for it. The advantage is that language compilers do not need to know details about different kinds of real processors. Since different .NET languages like C# or VB (and many more) produce IL, they are compatible on this level. This, together with other conventions like a common type system, allows you to use a DLL generated from VB code in a C# program, for instance.

当您运行.NET应用程序时,IL会在Windows上及时编译,也可以在Mono中提前编译.在这两种情况下,都会生成实际处理器的本地机器代码.完全编译的代码在REAL微处理器上执行!

The IL is compiled just in time on Windows when you run a .NET application and can also be compiled ahead of time in Mono. In both cases, native machine code for the actual processor is generated. This fully compiled code is executed on the REAL microprocessor!

另一个方面是您必须编写的编译器数量.如果您有 n 种语言,并且希望在 m 种处理器体系结构上运行它们,则需要 n 语言到语言的编译器 + m IL到本机代码编译器.没有这个中间的抽象层,您将需要 n×m 个编译器,并且这个数字可能比 n + m 还要高得多!

A different aspect is the number of compliers you have to write. If you have n languages and you want to run them on m processor architectures, you need n language-to-IL compliers + m IL-to-native-code compliers. Without this intermediate abstraction layer you would need to have n × m compliers and this can be a much higher number than just n + m!

这篇关于如果未解释C#,那么为什么需要VM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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