Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: String Literal Pool
|
Posted: Jun 17, 2002 8:58 AM
|
|
But of course the only strings in the literal pool would be the strings you literally typed (well, unless you are using a code geneator). This is likely to be a small amount of memory compared to what the computer has, unless you are one hell of a typist.
By the way, one of the advantages of this literal pool is that it saves memory. In this scenario:
String s = new String("Go placidly amid the noise and haste...");
String x = new String("Go placidly amid the noise and haste...");
You have two distinct and separate copies of the same string gobling up defenselsss little memory bits by the hundreds. While in this one:
String s = "Go placidly amid the noise and haste...";
// ... Several gigabytes of painstaking hand-typed code later...
String x = "Go placidly amid the noise and haste...";
Both s and x refer to the same String, leaving vast expanses of bored memory circuits with nothing to do.
|
|