OT: Language Stuff (WAS: Help getting experience)

Logan Kennelly plug-discuss@lists.plug.phoenix.az.us
Mon, 24 Jun 2002 18:48:44 -0700


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 24 June 2002 06:19 pm, Shawn Rutledge wrote:
> On Fri, Jun 21, 2002 at 11:09:44AM -0700, Isaac Sparrow wrote:
> > String a = "foo"
> > String b = "foo"
> >
> > if (a.equals(b))	// true
> >
> > if (a == b)	// false
>
> Maybe, but Java can also do string interning, which means that it will
> see that you already have "foo", probably don't need another one, and
> therefore make them both refer to the same instance.  While in general
> you should use .equals() (or .equalsIgnoreCase(), also very handy; or a
> Collator, for faster comparison of frequently-used strings, or for
> alphabetical sorting) to compare strings, if you use intern() on every
> String, you can use == to compare them, and it will be a lot faster to
> just compare references instead of looking at every character until a
> difference is found.  But internment (like interrment!) is itself an
> expensive operation.

I was under the impression that C++ did the same thing.  The compiler 
generates a "static" region of memory that is used for all strings.  
Although the feature is compiler dependant, if you use the same string in 
two spots, they should both reference the same string.  The gotcha' occurs 
when the compiler determines the string will be altered, in which case a 
copy of the string is made rather than using the original.

Furthermore, I was under the impression that this was all done at compile 
time, so it is not really expensive.  I would be extremely surprised if 
Java didn't do the same thing.  After all, a String is immutable so there 
is practically zero overhead with trying to figure that one out.

- -- 
						Logan Kennelly
      ,,,
     (. .)
- --ooO-(_)-Ooo--
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9F8wApNoctRtUIRQRAv4NAJ9wxIF2u2jITrDpM6puKMNugJy4MQCgjEO4
NJFvVStf/BJFkI99OIELnm0=
=LNpe
-----END PGP SIGNATURE-----