C# 有内联属性吗? [英] Does C# inline properties?

查看:32
本文介绍了C# 有内联属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C# 是否可以内联访问属性?我知道用于内联的 JIT 有 32 字节(指令?)限制,但它会内联属性还是只是方法调用?

Does C# inline access to properties? I'm aware of the 32 byte (instruction?) limit on the JIT for inlining, but will it inline properties or just pure method calls?

推荐答案

这取决于 JIT(据我所知,C# 编译器不进行任何内联),但我相信 JIT 会内联琐碎的属性大多数情况下.

It's up to the JIT (the C# compiler doesn't do any inlining as far as I'm aware), but I believe the JIT will inline trivial properties in most cases.

请注意,它不会内联从 MarshalByRefObject 派生的类型成员,其中包括 System.Windows.Forms.Control(通过 System.ComponentModel.Component).

Note that it won't inline members of types deriving from MarshalByRefObject which includes System.Windows.Forms.Control (via System.ComponentModel.Component).

我还看到 double 字段在通过属性访问时效率较低 - 这可能是因为它存在一些微妙之处(由于注册使用等).

I've also seen double fields end up being less efficient when accessed via properties - it could be that there are some subtleties around that (due to register use etc).

另请注意,64 位和 32 位 JIT 是不同的,包括它们对内联内容的处理.

Also note that the 64-bit and 32-bit JITs are different, including their treatment of what gets inlined.

我刚刚找到了一个 2004 博客条目 David Notario 提供的更多信息.然而,那是在 2.0 发布之前 - 现在看到至少 某些 已经改变了,我不会感到惊讶.反正可能会有兴趣.

I've just found a 2004 blog entry by David Notario with some more information. However, that was before 2.0 shipped - I wouldn't be surprised to see that at least some of it had changed now. Might be of interest anyway.

另一个问题提到了2008 Vance Morrison 博客条目提供更多信息.有趣的东西.

Another question referred to a 2008 Vance Morrison blog entry which gives more information. Interesting stuff.

这篇关于C# 有内联属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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