Yes,
in .NET memory is reallocated for each string concatenation.

In practice, the performance penalty is pretty minimal, especially
when compared to the overhead associated with the StringBuilder class.
 For a smalll number of operations, old-fashioned concatenation is
probably cheaper/faster than using StringBuilder.  What this small
number is open to debate (or testing).

What I usually do is concatenate when I have fewer than 10 or so
pieces to tie together.  If if it is long/complex string or
incorporates a lot of conditional logic, I will usually break out the
StringBuilder, which also tends to make code a little more readable
and easy to encapsulate.

I have also been making more and more use of the String.Format command
when working with a smalll number of strings that need to be put
together.  I find it cuts down on coding errors and makes it very easy
to change the format without worrying how to resplice a bunch of quote
characters.

On 5/12/05, DJ Sampson <[EMAIL PROTECTED]> wrote:
> 
> I have heard that the Stringbuilder class, now, is preferred - instead of 
> concatenation.
> 
> He told us that, (in DotNet) with concatenation (using +=), that the memory 
> space, with each addition/concatenation, was totally reallocated, instead of 
> being extended, like in VB6.
> 
> How much of this is correct and how much can concatenation negatively affect 
> an application?
> 
> (Does it really matter that much?)
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> 
> [Non-text portions of this message have been removed]
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 


-- 
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to