string-interning

Does the CLR/JVM keep one single intern pool for all running .net/java apps?

[亡魂溺海] 提交于 2019-11-29 10:46:30
The following is an extract from MSDN: The common language runtime conserves string storage by maintaining a table, called the intern pool, that contains a single reference to each unique literal string declared or created programmatically in your program. Consequently, an instance of a literal string with a particular value only exists once in the system. For example, if you assign the same literal string to several variables, the runtime retrieves the same reference to the literal string from the intern pool and assigns it to each variable. The Intern method uses the intern pool to search

Which debugging tool can list strings internalized?

本小妞迷上赌 提交于 2019-11-29 09:09:49
I am looking to a debugging tool that can list the strings that have been internalized? Ideally, I would like to put a mark and have a list of the strings that been added after that mark. Thanks in advance. Perhaps the easiest way is to use a bytecode viewer. Any String that is interned will be present in the constant_pool of the class file the String literal is included in. For instance, on a recent class file from another StackOverflow question I answered, I had the following String literal in my code: "sun.awt.noerasebackground" . This shows up in the constant pool as a 'String_info' type.

c# string interning

安稳与你 提交于 2019-11-29 06:32:36
I am trying to understand string interning and why is doesn't seem to work in my example. The point of the example is to show Example 1 uses less (a lot less memory) as it should only have 10 strings in memory. However, in the code below both example use roughly the same amount of memory (virtual size and working set). Please advice why example 1 isn't using a lot less memory? Thanks Example 1: IList<string> list = new List<string>(10000); for (int i = 0; i < 10000; i++) { for (int k = 0; k < 10; k++) { list.Add(string.Intern(k.ToString())); } } Console.WriteLine("intern Done"); Console

How does string interning work in Java 7+? [duplicate]

折月煮酒 提交于 2019-11-29 05:39:41
This question already has an answer here: String pool vs Constant pool 2 answers So, I realize the questions I'm about to ask relate to a topic that has been beaten to death time and time again, however, even after reading all of the answers and documentation I could find, I'm still kind of confused about string interning. Perhaps it's due to my lack of understanding for the JVM; perhaps it's due to the changes introduced in Java 7 depreciating many of the aforementioned answers and documentation. Either way, I'm stuck, and I'm hoping someone can help me understand the concept a bit more

Is string interning really useful?

醉酒当歌 提交于 2019-11-28 23:09:17
I was having a conversation about strings and various languages a while back, and the topic of string interning came up. Apparently Java and the .NET framework do this automatically with all strings, as well as several scripting languages. Theoretically, it saves memory because you don't end up with multiple copies of the same string, and it saves time because string equality comparisons are a simple pointer comparison instead of an O(N) run through each character of the string. But the more I think about it, the more skeptical I grow of the concept's benefits. It seems to me that the

Why does the String.intern() method return two different results? [duplicate]

旧街凉风 提交于 2019-11-28 07:19:27
问题 This question already has answers here : Why are the results of of str == str.intern() for these strings different? (4 answers) Closed 28 days ago . I have the code like this: String str1 = new StringBuilder("计算机").append("软件").toString(); System.out.println(str1.intern() == str1); //true String str2 = new StringBuilder("ja").append("va").toString(); System.out.println(str2.intern() == str2); //false String str3 = new StringBuilder("Str").append("ing").toString(); System.out.println(str3

Can we avoid interning of strings in java?

[亡魂溺海] 提交于 2019-11-28 06:05:23
问题 Can we completely disable interning of strings. It might not be really helpful, but just a thought. I can think atleast one point where it could be helpful i.e. during jvm tuning, controlling the size of the perm gen. For e.g. if I give out an OSGI framework and anyone can add any number of bundles of their own and each bundles string interning can completely screw up my tuning parameters. (Ofcourse I know that we should do tuning on a given fixed distro, but still...) Any thoughts!! 回答1:

Does the CLR/JVM keep one single intern pool for all running .net/java apps?

好久不见. 提交于 2019-11-28 04:04:28
问题 The following is an extract from MSDN: The common language runtime conserves string storage by maintaining a table, called the intern pool, that contains a single reference to each unique literal string declared or created programmatically in your program. Consequently, an instance of a literal string with a particular value only exists once in the system. For example, if you assign the same literal string to several variables, the runtime retrieves the same reference to the literal string

Which debugging tool can list strings internalized?

回眸只為那壹抹淺笑 提交于 2019-11-28 02:34:35
问题 I am looking to a debugging tool that can list the strings that have been internalized? Ideally, I would like to put a mark and have a list of the strings that been added after that mark. Thanks in advance. 回答1: Perhaps the easiest way is to use a bytecode viewer. Any String that is interned will be present in the constant_pool of the class file the String literal is included in. For instance, on a recent class file from another StackOverflow question I answered, I had the following String

Intern string literals misunderstanding?

孤街醉人 提交于 2019-11-27 15:42:46
I dont understand : MSDN says http://msdn.microsoft.com/en-us/library/system.string.intern.aspx Consequently, an instance of a literal string with a particular value only exists once in the system. For example, if you assign the same literal string to several variables, the runtime retrieves the same reference to the literal string from the intern pool and assigns it to each variable. Does this behavior is the Default (without intern ) ? or by using Intern method ? If its default , so why will I want to use intern? (the instance will be once already...) ? If its NOT default : if I write 1000