如何使用C#将变量存储在机器寄存器中? [英] How to let the variable be stored in a machine register using C#?

查看:104
本文介绍了如何使用C#将变量存储在机器寄存器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MSDN上引用并找到了register关键字,但它只在C ++中。

语法:

I had referenced at MSDN and found the register keyword, but it's only in C++.
Syntax:

register int x = 0;



你能用C#告诉我怎么做吗?



谢谢!


Can you tell me how to do that with C#?

Thanks!

推荐答案

你不要t。



即使在C ++中,寄存器关键字也只是一个建议。编译器可以自由忽略它。

http://stackoverflow.com/ questions / 3207018 / register-keyword-in-c [ ^ ]



在C#中,你没有编译机器代码;你正在编译MSIL。 JIT编译器稍后将MSIL编译为机器代码,应用各种优化以使您的代码在当前硬件上运行得更快。将注册提示添加到C#变量将完全没有意义。
You don't.

Even in C++, the register keyword is only a suggestion. The compiler is free to ignore it.
http://stackoverflow.com/questions/3207018/register-keyword-in-c[^]

In C#, you're not compiling to machine code; you're compiling to MSIL. The JIT compiler later compiles the MSIL to machine code, applying various optimizations to make your code run faster on the current hardware. Adding the register hint to a C# variable would be entirely pointless.


这篇关于如何使用C#将变量存储在机器寄存器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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