string-interning

deadlock on synchronized ( String intern())

懵懂的女人 提交于 2019-12-05 04:15:19
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.lang.Thread)0x28 pool-3-thread-2 waiting in a monitor (java.lang.Thread)0x27 pool-3-thread-3 waiting

Why does this string have a reference count of 4? (Delphi 2007)

自作多情 提交于 2019-12-04 22:57:01
This is a very Delphi specific question (maybe even Delphi 2007 specific). I am currently writing a simple StringPool class for interning strings. As a good little coder I also added unit tests and found something that baffled me. This is the code for interning: function TStringPool.Intern(const _s: string): string; var Idx: Integer; begin if FList.Find(_s, Idx) then Result := FList[Idx] else begin Result := _s; if FMakeStringsUnique then UniqueString(Result); FList.Add(Result); end; end; Nothing really fancy: FList is a TStringList that is sorted, so all the code does is looking up the string

How can I do string interning in C or C++?

牧云@^-^@ 提交于 2019-12-04 05:00:33
Is there something like intern() method in C or C++ like there is in Java ? If there isn't, how can I carry out string interning in C or C++? boost::flyweight< std::string > seems to be exactly what you're looking for. Is there something like intern() method in C like we have in Java ? Not in the standard C library. If there isn't, how to carry out string interning in C? With great difficulty, I fear. The first problem is that "string" is not a well-defined thing in C. Instead you have char * , which might point at a zero-terminated string, or might just denote a character position. Then you

Alternatives to Java string interning

喜欢而已 提交于 2019-12-04 01:11:55
问题 Since Java's default string interning has got a lot of bad press, I am looking for an alternative. Can you suggest an API which is a good alternative to Java string interning? My application uses Java 6. My requirement is mainly to avoid duplicate strings via interning. Regarding the bad press: String intern is implemented via a native method. And the C implementation uses a fixed size of some 1k entries and scales very poorly for large number of strings. Java 6 stores interned strings in

Why do (only) some compilers use the same address for identical string literals?

旧时模样 提交于 2019-12-02 15:41:44
https://godbolt.org/z/cyBiWY I can see two 'some' literals in assembler code generated by MSVC, but only one with clang and gcc. This leads to totally different results of code execution. static const char *A = "some"; static const char *B = "some"; void f() { if (A == B) { throw "Hello, string merging!"; } } Can anyone explain the difference and similarities between those compilation outputs? Why does clang/gcc optimize something even when no optimizations are requested? Is this some kind of undefined behaviour? I also notice that if I change the declarations to those shown below, clang/gcc

How does CompilationRelaxations.NoStringInterning actually work?

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:47:48
I am having problems demonstrating NoStringInterning [assembly: System.Runtime.CompilerServices.CompilationRelaxations(System.Runtime.CompilerServices.CompilationRelaxations.NoStringInterning)] class Program { static void Main(string[] args) { String s1 = "Friday"; String s2 = "Friday"; String s3 = "Friday"; String s4 = "Friday"; String s5 = "Friday"; String s6 = "Friday"; String s7 = "Friday"; String s8 = "Friday"; String s9 = "Friday"; // etc... Console.WriteLine(Object.ReferenceEquals(s1, s2)); Console.WriteLine(Object.ReferenceEquals(s1, s3)); Console.WriteLine(Object.ReferenceEquals(s1,

How does CompilationRelaxations.NoStringInterning actually work?

不羁的心 提交于 2019-12-01 05:16:54
问题 I am having problems demonstrating NoStringInterning [assembly: System.Runtime.CompilerServices.CompilationRelaxations(System.Runtime.CompilerServices.CompilationRelaxations.NoStringInterning)] class Program { static void Main(string[] args) { String s1 = "Friday"; String s2 = "Friday"; String s3 = "Friday"; String s4 = "Friday"; String s5 = "Friday"; String s6 = "Friday"; String s7 = "Friday"; String s8 = "Friday"; String s9 = "Friday"; // etc... Console.WriteLine(Object.ReferenceEquals(s1,

about intern in java

不想你离开。 提交于 2019-12-01 01:32:57
my question is if intern is working with string and string having a SPC(string pool constant) for it and intern concept also working with integer also, so is there any integer pool constant?if not then how its working? class InternExample { public void print() { Integer i=10; Integer j=10; String c="a"; String s="a"; System.out.println(i==j);// prints true System.out.println(c==s);//prints true } public static void main(String args[]) { new InternExample().print(); } } Prince John Wesley Added to @Joachim Sauer's answer, we can change the upper bound cache value . Some of the options are

about intern in java

无人久伴 提交于 2019-11-30 21:37:45
问题 my question is if intern is working with string and string having a SPC(string pool constant) for it and intern concept also working with integer also, so is there any integer pool constant?if not then how its working? class InternExample { public void print() { Integer i=10; Integer j=10; String c="a"; String s="a"; System.out.println(i==j);// prints true System.out.println(c==s);//prints true } public static void main(String args[]) { new InternExample().print(); } } 回答1: Added to @Joachim

Read the content of the string intern pool

风格不统一 提交于 2019-11-30 20:30:31
I would like to enumerate the strings that are in the string intern pool . That is to say, I want to get the list of all the instances s of string such that: string.IsInterned(s) != null Does anyone know if it's possible? Thanks to the advice of @HansPassant, I managed to get the list of string literals in an assembly. Which is extremely close to what I originally wanted. You need to use read assembly meta-data, and enumerate user-strings. This can be done with these three methods of IMetaDataImport : [ComImport, Guid("7DAC8207-D3AE-4C75-9B67-92801A497D44")] [InterfaceType(ComInterfaceType