Re: Where is stringbuilder?
- From: erewhon@xxxxxxxxxx (J French)
- Date: Thu, 19 Oct 2006 07:00:30 GMT
On Wed, 18 Oct 2006 12:14:46 -0500, Rob Kennedy <me3@xxxxxxxxxxx>
wrote:
<snip>
One of the reasons for StringBuilder is that in .Net (and Java), strings
are immutable -- once you create one, you cannot change its contents. In
Win32 Delphi, this statement is easy:
BigStr[L9 + Start] := SmallStr[L9];
In .Net, implementing that statement requires more work from the
compiler. It turns into something like this:
BigStr := Copy(BigStr, 1, L9 + Start - 1)
+ SmallStr[L9]
+ Copy(BigStr, L9 + Start + 1, MaxInt);
The old string gets discarded and a new string gets allocated because we
cannot change the contents of the old string, even when the reference
count is 1.
Fascinating,
so VB.NET does not support the equivalent of Mid$( S$, 2, 1 ) = "x"
What an odd idea
A string is just a block of memory
So in .Net, we need Stringbuilder because the old way of allocating a
long string and then filling it in later won't work -- it will result in
just as many memory allocations as before. StringBuilder purposely uses
something other than a string to holds its intermediate value, thus
avoiding the problem of immutable strings.
Hmm... I've generally found that Strings are about the most useful
and versatile way of allocating and manipulating blocks of memory
There is the old Concat Function, but it is not much use for this sort
of thing.
As it turns out, the Concat function is compiler magic. It does nothing
more than invoke the same routines that the "+" operator uses.
Drat, I expected to find the source for it.
How peculiar that Strings chars cannot be modified in .NET
Thanks for the info
.
- Follow-Ups:
- Re: Where is stringbuilder?
- From: Rob Kennedy
- Re: Where is stringbuilder?
- References:
- Where is stringbuilder?
- From: brett
- Re: Where is stringbuilder?
- From: Rob Kennedy
- Re: Where is stringbuilder?
- From: J French
- Re: Where is stringbuilder?
- From: Rob Kennedy
- Where is stringbuilder?
- Prev by Date: Re: Detecting WIN32 or .NET example in a compiler directive
- Next by Date: Re: Where is stringbuilder?
- Previous by thread: Re: Where is stringbuilder?
- Next by thread: Re: Where is stringbuilder?
- Index(es):
Relevant Pages
|