Static类是否会影响ASP.NET站点的性能 [英] Does Static class affect performance of ASP.NET site

查看:91
本文介绍了Static类是否会影响ASP.NET站点的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai伙计,


我有一个问题需要你的确切回答。我的问题是


静态类与实例类的区别如何在ASP.NET中使用静态

类,它会影响站点的速度或性能...?


因为我在数据库层使用静态类。但是我的一个朋友告诉我,静态类ll占用的空间比实例更多
类,它会影响性能。但是如果你使用Instance类

你可以创建对象,你就可以销毁那个对象,这样就可以了。

表现会很好。真的吗..?如果是这样......我想要适当的

解决方案。


提前致谢

Raja Chandrasekaran

Hai folks,

I have a question to get exact answer from you people. My question is

How Static class is differ from instance class and If you use static
class in ASP.NET, ll it affect speed or performance of site...?

Because I am using static class in my Database layer. But one of my
friend told me that "static class ll take more space than instance
class and it ll affect the performance. But if you use Instance class
you can create object and you can destroy that object, so that
performance ll be good." Is that true..? If so how... I want the proper
solution for this.

Thanks in advance
Raja Chandrasekaran

推荐答案

这在很大程度上取决于*在班级上的内容;如果这使用无状态

方法(即没有更新静态字段),那么我没有看到任何问题

静态 - 事实上它消除了对偶数的需要创建任何对象(每个

调用)[虽然在任何有用的例子中这将是如此简单的

最小的影响]。


AVOID虽然在这些类上使用有状态的静态属性/字段;

记住很多线程都可以和类通话,所以要么你要b / b
得到线程争用错误当多个客户端正在连接时,或者你将会b
广泛阻塞 - 一次只能产生一个有用的线程。


所以:

*无状态静态应该没问题

*有状态实例应该没问题

*性能不是真正的因素,除非这些是庞大的类,

如果你遇到更大的问题


Marc
It depends largely on what resides *on* the class; if this uses stateless
methods (i.e. no static fields are updated), then I don''t see any problem
with static - in fact it removes the need to even create any objects (per
call) [although in any useful example this is going to be so trivially
minimal impact].

AVOID using stateful static properties / fields on such classes though;
remember that many threads can be talking to the class, so either you will
get thread-race bugs when multiple clients are connecting, or you''ll
wide-spread blocking - essentially yielding only 1 useful thread at a time.

So:
* stateless static should be fine
* stateful instance should be fine
* performance isn''t really a factor unless these are mammoth classes, in
which case you have bigger problems

Marc


>即没有更新静态字段

应该读取

没有使用静态字段
> i.e. no static fields are updated
should have read
"no static fields are used"




Marc Gravell写道:

Marc Gravell wrote:
即没有更新静态字段


应该已阅读
没有使用静态字段


should have read
"no static fields are used"




感谢comment.its罚款。但是,如果我使用普通类与静态

成员和函数......那将是什么优点和缺点...

我想提高我的应用程序的性能以所有

的方式......



Thanks for comment.its fine. But If I use Normal class with static
members and functions... what ll be the advantages and disadvantages...
Y I am aasking to increase the performance of my application by all the
ways...


这篇关于Static类是否会影响ASP.NET站点的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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