简体   繁体   English

没有.NET Framework的C#

[英]C# without .NET Framework

Writing fast native applications, with API calls and etc, in a modern cross platform programming language like C# would be awesome, wouldn't it? 使用像C#这样的现代跨平台编程语言编写快速的本机应用程序,使用API​​调用等,会很棒,不是吗? For example if you want to write a simple utility for helping IT people with installing things, which wouldn't need another components, in an easy and modern programming language? 例如,如果您想编写一个简单的实用程序来帮助IT人员以简单而现代的编程语言安装不需要其他组件的东西? or if you want to write a 3D game, it should be fast, and JIT would just make it slower... 或者如果你想写一个3D游戏,它应该很快,而JIT会让它变得更慢......

Why, why isn't it possible? 为什么,为什么不可能呢? Why there are no native modern programming languages for these things? 为什么这些东西没有原生的现代编程语言?

C# and .Net are native code. C#和.Net 本机代码。 I think you misunderstand the JITter. 我想你误解了JITter。 It's not a VM. 它不是虚拟机。 AC# program is compiled to fully native code before any of it is executed. AC#程序在执行任何程序之前编译为完全本机代码。

Now, the "needing other components" part is a concern. 现在,“需要其他组件”部分是一个问题。 Give it time, though. 但是请给它时间。 You'll be hard pressed to find a windows installation these days without at least .Net 2.0, and even a couple mainstream linux distros include mono out of the box. 这些天你很难找到一个没有.Net 2.0的Windows安装,甚至一些主流的Linux发行版也包括开箱即用的单声道。

Don't assume the JIT makes things slower. 不要认为JIT让事情变得更慢。 The JIT can optimize for the exact computer running the application rather than a generic computer like a 386 or Pentium. JIT可以针对运行应用程序的精确计算机进行优化,而不是像386或Pentium这样的通用计算机。 It can even make better speed/memory trade-off decisions when generating code because it knows exactly what's available. 它甚至可以在生成代码时做出更好的速度/内存权衡决策,因为它确切地知道可用的内容。 And if JIT still makes things slower, you can NGEN them so that JITting is all done beforehand. 如果JIT仍然让事情变慢,你可以让他们认真对待,以便JITting事先完成。

As proof of this, consider that Quake has been ported to the CLR a couple of times, and in my personal tests, the frames per second have been faster when Quake runs on the CLR about half the times I demo it. 作为证明这一点,考虑到Quake已被移植到CLR几次,并且在我的个人测试中,当Quake在CLR上运行大约一半的时间时,每秒的帧速度更快

已经证明编译的.NET程序运行速度与C一样快。如果您希望它超精简,请将其编译为原生处理器的程序集。

You can use the Microsoft NGEN.EXE tool to create a native image of a .NET assembly. 您可以使用Microsoft NGEN.EXE工具来创建.NET程序集的本机映像。 See MSDN NGEN documentation . 请参阅MSDN NGEN文档 Microsoft already though about what you're getting at here. 微软已经知道你在这里得到了什么。

Microsoft also makes ILMERGE.EXE tool to merge multiple assembly files into one. Microsoft还使ILMERGE.EXE工具将多个程序集文件合并为一个。 This might border on optimization and speed too. 这也可能与优化和速度有关。

So, does this mean that we could fully compile and link a C# program using (limited) .NET calls into a standalone EXE that would run without .NET being installed at all? 那么,这是否意味着我们可以使用(有限的).NET调用将C#程序完全编译并链接到一个独立的EXE中,该EXE在没有安装.NET的情况下运行?

FYI: Checking a server estate of some 5000 servers revealed about 200 without even .NET 2.0. 仅供参考:检查大约5000台服务器的服务器资产,显示大约200台服务器甚至没有.NET 2.0。

This causes problems for code that must run on "all Windows instances". 这会导致必须在“所有Windows实例”上运行的代码出现问题。 With .NET 4.0+ not including 2.0 this gets worse as both new AND old Windows machines might not have the 'right' .NET 随着.NET 4.0+不包括2.0,这会变得更糟,因为新旧Windows机器可能没有'正确'的.NET

As a side note, Mono has full ahead of time compiling, eliminating the runtime. 作为旁注,Mono已经完全提前编译,从而消除了运行时间。 (I think that's how they get away running on iPhone, which prohibits any JIT.) (我认为这就是他们如何在iPhone上运行,禁止任何JIT。)

有,C。C可以用来写任何应用程序,永远!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM