Re: Strings.. Objects or not???

From: Patrick Steele [MVP] (patrick_at_mvps.org)
Date: 07/09/04


Date: Fri, 9 Jul 2004 09:52:58 -0400

In article <40ee9f0e$0$552$ed2619ec@ptn-nntp-reader02.plus.net>, s@v.c
says...
> Thanks all for your replies but I'm still confused.
>
> So coding "veg" anywhere will only ever create one object?

Yes. It's called "String Interning" and the String.Intern method has a
description of what it's for. Basically (from the docs):

"The common language runtime conserves string storage by maintaining a
table, called the intern pool, that contains a single reference to each
unique literal string declared or created programmatically in your
program. Consequently, an instance of a literal string with a particular
value only exists once in the system."

-- 
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele


Relevant Pages

  • Re: how to make two references to one string that stay refered to the same string reguardless of the
    ... You can use the string interning pool. ... Both references point to the same "foo" in memory, ... This can be a tremendous memory saver. ... String interning is considerably slower than simple assignment. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: hashtable and casing
    ... The benifit> is I can store the domain name and not worry about case and return the user> supplied case without storing an state, ... However, this comes at a cost> because all string compare operations now must be case sensitive such as> endswith, etc. ... This can be leveraged with string interning for> duplicates. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strings.. Objects or not???
    ... > Thanks all for your replies but I'm still confused. ... It's called "String Interning" and the String.Intern method has a ... "The common language runtime conserves string storage by maintaining a ... an instance of a literal string with a particular ...
    (microsoft.public.dotnet.general)
  • Re: Strings.. Objects or not???
    ... > Thanks all for your replies but I'm still confused. ... It's called "String Interning" and the String.Intern method has a ... "The common language runtime conserves string storage by maintaining a ... an instance of a literal string with a particular ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Replacing a motherboard (?)
    ... MIKE>> In what way have you been told that your motherboard is 'on it's ... after a long string of replies to an earlier ...
    (microsoft.public.windowsxp.hardware)