简体   繁体   English

应用程序变量和性能?

[英]Application variables and performance?

使用更多数量的应用程序变量会影响asp.net网站的性能吗?

没有任何重大意义。

As long as they're local variables, not. 只要它们是局部变量,就不是。 If static variables, in extreme cases it could (eg in case of an ever-growing collection) but in normal use cases it will not have any noticeable effect. 如果是静态变量,则在极端情况下(例如,在收藏不断增长的情况下)可以,但是在正常使用情况下,它不会产生任何明显的影响。

You mean variables attached to the "Application" object, right? 您是指附加到“应用程序”对象的变量,对吗?

No, it shouldn't be a problem, provided you realise: 不,只要您意识到,这应该不成问题:

  • They are shared by different threads so there may be concurrency problems 它们由不同的线程共享,因此可能存在并发问题
  • They are NOT shared by different worker processes, so you can't guarantee exactly one instance, even if you have only one machine 它们不会由不同的工作进程共享,因此即使您只有一台计算机,也无法保证一个实例

If you create large objects during run-time it definitely affects performance. 如果在运行时创建大对象,则肯定会影响性能。

If you create them all during initialization they can affect run time if you access one then another then one and another back and forth which may cause paging (look up the term). 如果您在初始化期间全部创建它们,则可能会影响运行时间,如果您访问一个然后访问另一个,则一个又一个来回访问,这可能会导致分页(查找术语)。

Variables like int, char, double, ... don't affect performance, large arrays of them can. 诸如int,char,double之类的变量不会影响性能,但它们的大数组会影响性能。

I recommend you read about how the cache works and how operating system allocate/deallocate memory. 我建议您阅读有关缓存的工作方式以及操作系统如何分配/取消分配内存的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM