3 ms·
For those interested in the same feature in plain old C, have a look at the DSO Howto, section 2.4.2 "Forever const" and the LD flags SHF_MERGE and SHF_STRING.
by gioele 12y ago
For those interested in the same feature in plain old C, have a look at the DSO Howto, section 2.4.2 "Forever const" and the LD flags SHF_MERGE and SHF_STRING.
With a little bit of magic, C compilers and linkers are even allowed to turn (simplified example)
const char s1[] = "some string";
const char s2[] = "string";
into
const char s1[] = "some string";
const char s2[] = s1+5;
and place these constants in a read-only section shared between multiple loaded instances of the same library or program.
- riffraff 12y agoI think it's standard java behaviour to .intern string constants appearing in code (i.e. since they are immutable, just share them). The new thing is that the JVM is going to do this automatically for strings that _don't_ exist at compile time, IIUC.