Performance Overheads when Using Resource Files (.resx)

前端 未结 1 856
盖世英雄少女心
盖世英雄少女心 2021-02-13 10:32

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

1条回答
  •  长情又很酷
    2021-02-13 11:13

    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.

    0 讨论(0)
提交回复
热议问题