string-interning

String-interning at compiletime for profiling

旧时模样 提交于 2019-12-30 11:51:21
问题 Context I am working on an instrumenting profiler, that enables you to name different measurements by string. So for example: MEASURE_SCOPE(text_rendering_code); ... MEASURE_SCOPE(password_hashing); ... MEASURE_START(system_call); ... MEASURE_STOP(system_call); where the macros would be defined like this: #define MEASURE_START(name) save_start_event(get_timestamp(), #name); #define MEASURE_STOP(name) save_stop_event(get_timestamp(), #name); #define MEASURE_SCOPE(name) Profiling_Class object#

Has String.Intern had the value?

我是研究僧i 提交于 2019-12-23 20:05:34
问题 String.Intern has a special pool for strings which can later be retrieved. Is there any way for me to know that the specified string was taken from the pool , and was NOt newly created ? example : string s1 = "MyTest"; string s2 = new StringBuilder().Append("My").Append("Test").ToString(); string s3 = String.Intern(s2); Console.WriteLine((Object)s2==(Object)s1); // Different references. Console.WriteLine((Object)s3==(Object)s1); // The same reference. s3 ref val was taken from the pool is

Search cost of string interning and declaration of literal strings

南楼画角 提交于 2019-12-22 05:33:12
问题 Two Questions. When we declare literal strings, we search whether there is the same string in string pool of heap. Is this also an interning (method intern of class String )? In my thought, each literal string declaration needs a binary search or something so it costs at least log(n) when n is number of existing strings in the pool. And if there are many strings in the pool, it may be high cost. (maybe tradeoff of searching cost and memory?) On this point of view, it might be dangerous to

deadlock on synchronized ( String intern())

邮差的信 提交于 2019-12-22 04:48:10
问题 I user sun jdk 1.5 ThreadPoolExecutor( 24, 24,60,TimeUnit.SECONDS, new LinkedBlockingQueue()). soemtime I use jdb tool to find the status of all threads in thread pool are " waiting in a monitor", the code is : String key = getKey(dt.getPrefix(), id); synchronized (key.intern()) { -----> Is there a problem in "synchronized (key.intern()) " ? I get following informatnio using jdb tool, the status of 24 threads is "waiting in a monitor", it means 24 threads are deadlock at "key.intern()". (java

Are interned strings excepted from garbage collection in .NET?

余生颓废 提交于 2019-12-18 08:47:11
问题 I am trying to reduce time it takes to do a Gen2 collection. My app creates and holds a large number of string objects, which persist through its life. Reducing number of scanned objects should reduce GC time. I was wondering whether intern pool is excepted from garbage collection. There isn't anything to collect there anyway. If so, I could intern all these strings and speed up GC. 回答1: I made a quick test and interning of strings does not seem to save them from scanning by GC. At least not

c# string interning

我的梦境 提交于 2019-12-18 04:45:10
问题 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 <

String intern() behaviour

心不动则不痛 提交于 2019-12-17 21:59:12
问题 From the javaDocs of String class's intern method : When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned. Consider the following use-cases: String first = "Hello"; String second = "Hello"; System.out.println(first == second); String third = new String("Hello");

String interning?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 18:45:34
问题 The second ReferenceEquals call returns false. Why isn't the string in s4 interned? (I don't care about the advantages of StringBuilder over string concatenation.) string s1 = "tom"; string s2 = "tom"; Console.Write(object.ReferenceEquals(s2, s1)); //true string s3 = "tom"; string s4 = "to"; s4 += "m"; Console.Write(object.ReferenceEquals(s3, s4)); //false When I do String.Intern(s4); , I still get false. Here, both s3 and s4 are interned but their references are not equal? string s3 = "tom";

Intern string literals misunderstanding?

匆匆过客 提交于 2019-12-17 14:09:10
问题 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

Garbage collection on intern'd strings, String Pool, and perm-space

怎甘沉沦 提交于 2019-12-17 07:52:12
问题 After exploring java's string internals I've grown confused on what is referred to as the "perm space." My understanding initially of it was that it held String literals as well as class meta data as explained in this question. I've also read about the String.intern() method and that it places String s into the String Pool returning a reference to unique instance of it. It is my understanding that this is the same string pool holding String literals that exists in the JVM's perm-space. It