服务表现间接费用使用资源文件时(的.resx) [英] Performace Overheads when Using Resource Files (.resx)

查看:149
本文介绍了服务表现间接费用使用资源文件时(的.resx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,我所知道的关于这一主题的下列问题:




  1. Are~~MD有任何性能问题或警告与资源(的.resx)文件?


  2. 是字符串资源(的.resx)的属性保存在内存中?




等。但是,我没有发现任何对这些问题的满意答案(他们是不够具体)。



我也知道的 MSDN 关于这一主题的网页,但这些似乎也吝啬有关的技术信息使用资源文件的开销。






我的困境是,我们即将踏上一个合理的大型WinForms应用程序的本地化。我在此阶段关注的是关于从例如一个嵌套循环内从一个.resx文件访问资源的性能。目前的代码的一小部分,我们本地化(列名,行标题等,为 DataGridView的等),我们正在兑现资源相关类的全局变量和使用这些。



如何是从的.resx访问的资源(它们是包含在编译时组装?),是从有兑现这些资源提高性能和使用全局变量进行访问?



感谢您的时间。


解决方案

字符串资源被缓存在内存中。你看那个在Resources.Designer.cs生成的代码。



它使用的 System.Resources.ResourceManager 和这样做的琴弦缓存。



另外请注意这ResourceManager的构造。它提到,你可以改变缓存策略:




此构造函数使用系统提供的ResourceSet实现。
。要使用自定义资源文件格式,你应该从
的ResourceSet类派生,重写GetDefaultReader和GetDefaultWriter
方法,并通过该类型到ResourceManager(字符串,组装,
型)构造函数。使用自定义的ResourceSet能
控制有用的资源缓存策略
或支持自己的资源
文件格式,但一般没有必要的。


< /块引用>

(我的重点)



有关文档的ResourceSet 明确表示:



< BLOCKQUOTE>

的ResourceSet类枚举了一个多IResourceReader,装载每个名称和值,并将它们存储在一个Hashtable





所以我们知道确切的缓存策略,你会在默认情况下得到的。



既然你似乎不相信我! :)



(1)看的构造函数的的ResourceManager(字符串baseName的,大会组装)。它指出:





此构造函数使用系统提供的ResourceSet实施





(2)现在看的documentation为的ResourceSet 。它指出:





的ResourceSet类枚举了一个多IResourceReader,装载每个名称和值,并将它们存储在一个Hashtable。





因此,该缓存行为确实是记录在MSDN,另外还可以验证这是通过使用ReSharper的检查落实情况发生。


Note, I am aware of the following questions on this topic:

  1. Are there any performance issues or caveats with resource (.resx) files?

  2. Are string resources (.resx) properties kept in memory?

et al. However, I don't find any of the answers in these questions satisfactory (they are not concrete enough).

I am also aware of the MSDN pages on this topic, but these also seem to skimp on the technical information regarding the overheads of using resource files.


My predicament is that we are about to embark on the localisation of a reasonably large sized WinForms application. My concern at this stage is about the performance of accessing resources from a .resx file from within a nested loop for example. Currently for the small part of the code we have localised (Column Names, Row Headers etc. for DataGridView etc.) we are cashing the resources in global variables of the relevant class and using those.

How are resources from the .resx accessed (are they included in the assembly at compile-time?) and is there a performance benefit from cashing those resources and using global variables for access?

Thanks for your time.

解决方案

String resources are cached in memory. Look at the code that's generated in "Resources.Designer.cs".

It uses a System.Resources.ResourceManager, and this does caching of the strings.

Also note this ResourceManager constructor. It mentions that you can change caching strategy:

This constructor uses the system-provided ResourceSet implementation. To use a custom resource file format, you should derive from the ResourceSet class, override the GetDefaultReader and GetDefaultWriter methods, and pass that type to the ResourceManager(String, Assembly, Type) constructor. Using a custom ResourceSet can be useful for controlling resource caching policy or supporting your own resource file format, but is generally not necessary.

(my emphasis)

The documentation for ResourceSet explicitly says:

The ResourceSet class enumerates over an IResourceReader, loading every name and value, and storing them in a Hashtable

So we do know the exact caching strategy that you'll get by default.

[EDIT] Since you don't seem to believe me! :)

(1) Look at the documentation for the constructor ResourceManager(string baseName,Assembly assembly). It states:

This constructor uses the system-provided ResourceSet implementation.

(2) Now look at the documentation for ResourceSet. It states:

The ResourceSet class enumerates over an IResourceReader, loading every name and value, and storing them in a Hashtable.

Therefore this caching behaviour is indeed documented in MSDN, and additionally you can verify that this is what is happening by using Resharper to inspect the implementation.

这篇关于服务表现间接费用使用资源文件时(的.resx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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