English 中文(简体)
在网上编码中人工操作外衣的好想法是什么?
原标题:When is it a good idea to intern strings manually in a .Net code?

The reference is here: http://msdn.microsoft.com/en-us/library/system.string.intern.aspx

Looks like this is done automatically by the compiler a lot, but can also be done manually. Please correct me if I am wrong and shed some more light on this. Does it matter whether the language is C#, VB.Net, C++/CLI, other?

感谢。

最佳回答

我这样做的是,如果存在重复价值的良好机会(几乎是一 en,但并非相当高)。 播下数千份记录后,可提供<>重大记忆惠益。 然而,在这种情况下,你可能宁愿使用separate intern cache,以避免污蔑共有的(或可能是共有的罚款;这取决于具体情况)。

但关键之处是:一种情况是,你可能拥有具有相同价值的多种不同事例。 帝国化是当地的一个大候选人。 还应当指出的是,在检查被拦截的海滩方面,有几处CPU的间接费用(如你增加数据,间接管理),因此,如果能够让被污染的物体活起来超过基因-0;如果它们总是能够迅速收集anyway,就应当避免这种情况。 那么,用相隔的版本交换这些物品是值得的。

问题回答

在貌相显示它给业绩带来好处时,它就是一个好的想法。

It is done by the runtime, but a language could introduce its own string type with a different behavior. It is only done for literal strings. If you want to intern dynamically created strings, you can do so. For one thing it makes comparing strings really simple, but keep in mind that while some operations will benefit from interning others will not. E.g. interned strings are not released until process shutdown (as they are rooted by the internal structure, see this question for details), so if you intern a lot of strings manually, the process will carry around a lot of memory.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签