加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用资源文件时执行开销(.resx)

发布时间:2020-12-15 17:49:45 所属栏目:百科 来源:网络整理
导读:请注意,我了解以下有关此主题的问题: Are there any performance issues or caveats with resource (.resx) files? Are string resources (.resx) properties kept in memory? et al.但是,我在这些问题中找不到任何答案令人满意(他们不够具体). 我也了解了
请注意,我了解以下有关此主题的问题:

> Are there any performance issues or caveats with resource (.resx) files?
> Are string resources (.resx) properties kept in memory?

et al.但是,我在这些问题中找不到任何答案令人满意(他们不够具体).

我也了解了关于这个主题的MSDN页面,但是这些页面似乎还在撇开有关使用资源文件的开销的技术信息.

我的困境是,我们即将着手进行一个相当大型的WinForms应用程序的本地化.我在这个阶段的关注是关于从嵌套循环中的.resx文件访问资源的性能.目前,对于代码的一小部分,我们已经本地化(DataGridView等的列名称,行头等),我们正在将相关类的全局变量中的资源进行融合并使用这些资源.

来自.resx的资源如何被访问(它们在编译时包含在程序集中),并且通过结合这些资源并使用全局变量进行访问,是否具有性能优势?

谢谢你的时间.

解决方法

字符串资源被缓存在内存中.看看在“Resources.Designer.cs”中生成的代码.

它使用了一个System.Resources.ResourceManager,这是缓存字符串.

另请注意this ResourceManager constructor.它提到您可以更改缓存策略:

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.

(我的重点)

documentation for ResourceSet明确表示:

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

所以我们知道您将默认获得的确切的缓存策略.

因为你似乎不相信我!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读