我可以检查C#编译器内联方法调用? [英] Can I check if the C# compiler inlined a method call?

查看:99
本文介绍了我可以检查C#编译器内联方法调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个XNA游戏,我做的每像素碰撞检测。它检查通过改变一个int和位的ORing这这样做,一般是很难的循环来阅读和理解。<​​/ P>

我想补充的私有方法,如私人布尔IsTransparent(INT pixelColorValue)来使循环更加易读,但我不想方法调用的开销因为这是非常敏感的表现code。

有没有办法强制编译器内联这个电话,否则我将做我只是希望,编译器会做这种优化?

如果没有办法迫使这一点,是有办法检查方法,内联,阅读的短拆卸?请问方法反射显示出来,如果​​它是内联并没有其他呼叫者是否存在?

编辑:我不能强迫它,这样我就可以检测到它。


解决方案

没有你不能。更有甚者,谁上内联决定一个不是VS编译器,它需要你code并将其转换成IL,但JIT编译器是需要IL并将其转换成机器code。这是因为只有JIT编译器知道有足够的了解处理器架构,以决定是否将一个方法是内联合适,因为它的指令流水线和缓存大小之间的权衡。

因此​​,即使在看.net反射不会帮你。

I'm writing an XNA game where I do per-pixel collision checks. The loop which checks this does so by shifting an int and bitwise ORing and is generally difficult to read and understand.

I would like to add private methods such as private bool IsTransparent(int pixelColorValue) to make the loop more readable, but I don't want the overhead of method calls since this is very performance sensitive code.

Is there a way to force the compiler to inline this call or will I do I just hope that the compiler will do this optimization?

If there isn't a way to force this, is there a way to check if the method was inlined, short of reading the disassembly? Will the method show up in reflection if it was inlined and no other callers exist?

Edit: I can't force it, so can I detect it?

解决方案

No you can't. Even more, the one who decides on inlining isn't VS compiler that takes you code and converts it into IL, but JIT compiler that takes IL and converts it to machine code. This is because only the JIT compiler knows enough about the processor architecture to decide if putting a method inline is appropriate as it’s a tradeoff between instruction pipelining and cache size.

So even looking in .NET Reflector will not help you.

这篇关于我可以检查C#编译器内联方法调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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