难道C#的静态函数比非静态函数有更好的表现,超越减少内存使用情况? [英] Do C# static functions perform better than nonstatic functions, beyond reduced memory usage?

查看:202
本文介绍了难道C#的静态函数比非静态函数有更好的表现,超越减少内存使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为公共私人 静态目标必须具有降低存储器的使用,由于这样的事实,有在存储器中的静态目标的只有一个副本。

I assume that public or private static targets must have reduced memory usage, due to the fact that there is only one copy of the static target in memory.

好像因为一个方法是静态的,可能使该方法一电位点用于通过以外什么是可能的非静态功能CLR的编译器进一步优化。只是站不住脚的理论的,所以我来问大家。

It seems like because a method is static that might make the method a potential point for further optimization by the CLR compiler beyond what is possible with a non-static function. Just a flimsy theory though, so I've come to ask you all.

不要静态 公共私人方法提供了超越减少内存使用量增加任何性能优势?

Do static public or private methods provide any increased performance benefit beyond reduced memory usage?

(注:我没有兴趣在过早优化的问题,谈话的反应当然,这是合理的建议我按照日常,但是,这并不意味着优化是没有必要的时候(双负),让我沉醉。!。我的好奇心,至少)

(Note: I'm not interested in responses that talk on the problems of premature optimization. Certainly that's sound advice I follow everyday, but that does not mean optimization is not necessary at times. (double negative!). Allow me to indulge my curiosity, at the least)

推荐答案

从的静态类和静态类成员(C#编程指南)

一个呼叫到静态方法生成微软
中间语言(MSIL)一
调用指令,而
A调用一个实例方法生成
A callvirt指令,这也
检查空对象的引用。
然而,大部分时间在两个
间的
表现差异不是显著

A call to a static method generates a call instruction in Microsoft intermediate language (MSIL), whereas a call to an instance method generates a callvirt instruction, which also checks for a null object references. However, most of the time the performance difference between the two is not significant.

这篇关于难道C#的静态函数比非静态函数有更好的表现,超越减少内存使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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