可以用 MSIL 编码吗?
我只是想知道这是否可以做到。如果它不能带来一些显着的性能优势,我不打算这样做。我是一名网络和游戏开发人员,但我通常不使用 C# 开发游戏。
I am just curious to know if this can be done or not. I don't plan on doing it if it dosen't pack some significant performance benefits. I am a web and game developer but I usually don't develop games in c#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,这是可能的 - 您可以使用
ilasm
(随.NET SDK一起提供)来编译您的代码。但是,Visual Studio 中不提供对此的 IDE 支持。您可以从中获得任何无法通过其他方式获得的性能优势 - 具体来说,C++/CLI 涵盖了所有低级 CLR 功能,这些功能可能会提供一些好处,并且无法从 C# 或 VB 访问- 最值得注意的是,无复制 (ref
) 拆箱、普通无界函数指针(与委托相反)以及相关的calli
IL 指令和ref(CLI 术语中的托管指针)局部变量(而不只是参数)。
Yes, it is possible - you can use
ilasm
(comes with .NET SDK) to compile your code. There's no IDE support for that in Visual Studio, however. There aren't any performance benefits that you can derive from this that you wouldn't be able to get by other means - specifically, C++/CLI covers all low-level CLR features that may provide some benefit and are inaccessible from C# or VB - most notably, no-copy (ref
) unboxing, plain unbounded function pointers (as opposed to delegates) and the associatedcalli
IL instruction, andref
(managed pointer in CLI parlance) local variables (as opposed to just parameters).是的,你可以; Microsoft 的 MSIL 汇编程序 (ilasm.exe) .NET SDK 中的 .NET 会将您的 IL 编译为可执行代码。我看不出有任何理由这样做,除非是在非常集中的领域,您发现在这些领域可以获得显着的性能优势。
这是一篇详细的文章,描述了如何做到这一点。
Yes, you can; Microsoft's MSIL Assembler (ilasm.exe) from the .NET SDK will compile your IL to executable code. I can't see any reason to do this, except in very focused areas, where you've found a substantial performance benefit to be gained.
Here's a detailed, if dated, article describing how to do this.
或者您可以从 C# 发出一些 CIL。 将对象文字提供给 ILGenerator
Or you could emit a bit of CIL from your C#. Feeding an object literal to ILGenerator
#Develop (Sharp Develop) IDE 有一个用于 il 项目的插件。我没有使用过它,所以我不确定它能提供多少帮助。 http://www.icsharpcode.net/OpenSource/SD/
The #Develop (Sharp Develop) IDE has a plugin for il projects. I haven't used it, so I'm not sure how much help it provides. http://www.icsharpcode.net/OpenSource/SD/