<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Reacties op: String Concatenation vs Memory Allocation</title>
	<atom:link href="http://www.cumps.be/string-concatenation-vs-memory-allocation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/</link>
	<description>Living my life...</description>
	<lastBuildDate>Sat, 12 Dec 2009 22:49:53 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Door: C# tips &#38; tricks: String Concatenation, Best practices &#171; Indian Developer</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-460</link>
		<dc:creator>C# tips &#38; tricks: String Concatenation, Best practices &#171; Indian Developer</dc:creator>
		<pubDate>Mon, 17 Aug 2009 14:24:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-460</guid>
		<description>[...] String Concatenation vs Memory Allocation [...]</description>
		<content:encoded><![CDATA[<p>[...] String Concatenation vs Memory Allocation [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: The myth of System.Text.StringBuilder &#171; @&#34;figurative&#34;;</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-456</link>
		<dc:creator>The myth of System.Text.StringBuilder &#171; @&#34;figurative&#34;;</dc:creator>
		<pubDate>Mon, 26 Jan 2009 06:50:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-456</guid>
		<description>[...] http://blog.cumps.be/string-concatenation-vs-memory-allocation/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://blog.cumps.be/string-concatenation-vs-memory-allocation/" rel="nofollow">http://blog.cumps.be/string-concatenation-vs-memory-allocation/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: David Cumps</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-457</link>
		<dc:creator>David Cumps</dc:creator>
		<pubDate>Mon, 19 Jan 2009 20:25:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-457</guid>
		<description>@Sumesh
Way1: // 4 string instances, 3 pieces, 1 format
Way2: // 7 string instances, 4 pieces and 3 concat operations
Way3: / 4 instances, 4 array pieces, 1 concat

Way4 however would just replace Way2 by leaving out the &quot;=&quot; signs and your result is a single string in IL code ;)

You&#039;d have to run your samples in a loop (100?) and look at the profiler in that case. If interning works, it doesn&#039;t really matter much, since you&#039;d have 4/5 strings at most, if it&#039;s not at work you should see ending up with 400+ ish strings</description>
		<content:encoded><![CDATA[<p>@Sumesh<br />
Way1: // 4 string instances, 3 pieces, 1 format<br />
Way2: // 7 string instances, 4 pieces and 3 concat operations<br />
Way3: / 4 instances, 4 array pieces, 1 concat</p>
<p>Way4 however would just replace Way2 by leaving out the &#8220;=&#8221; signs and your result is a single string in IL code <img src='http://www.cumps.be/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>You&#8217;d have to run your samples in a loop (100?) and look at the profiler in that case. If interning works, it doesn&#8217;t really matter much, since you&#8217;d have 4/5 strings at most, if it&#8217;s not at work you should see ending up with 400+ ish strings</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Ed</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-459</link>
		<dc:creator>Ed</dc:creator>
		<pubDate>Fri, 09 Jan 2009 02:32:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-459</guid>
		<description>A good article, but I think what needs mentioning is that string.Format is not for concatenating strings, it&#039;s for formatting them, typically in a culture-sensitive manner.

String.Format is powerful, but powerful tools often sacrifice raw speed for robust features.

String.Format is very readable, and for localization issues it&#039;s extremely powerful. If you have a resource file that has a literal called MyFormat being:
 en-US = &quot;There are {0} cars in {1} garages.&quot;
 fr-FR = &quot;Dans {1} garage, il est {0} auto.&quot;
(pardon my French, just for illustration)

String.Format is also good in this manner because the culture-specific format string can have date/time, precision and other formatting which will vary culture to culture. String.Format allows the code to move from culture-hardcoded to culture agnostic and is very portable and robust at the same time.

String.Concat on the other hand is raw speed. If you can get away with it, use it.

If you have a variable number of concatenations, then a StringBuilder is the way to go.

If you need to format strings and address internationalization issues, there&#039;s nothing better than string.format.</description>
		<content:encoded><![CDATA[<p>A good article, but I think what needs mentioning is that string.Format is not for concatenating strings, it&#8217;s for formatting them, typically in a culture-sensitive manner.</p>
<p>String.Format is powerful, but powerful tools often sacrifice raw speed for robust features.</p>
<p>String.Format is very readable, and for localization issues it&#8217;s extremely powerful. If you have a resource file that has a literal called MyFormat being:<br />
 en-US = &#8220;There are {0} cars in {1} garages.&#8221;<br />
 fr-FR = &#8220;Dans {1} garage, il est {0} auto.&#8221;<br />
(pardon my French, just for illustration)</p>
<p>String.Format is also good in this manner because the culture-specific format string can have date/time, precision and other formatting which will vary culture to culture. String.Format allows the code to move from culture-hardcoded to culture agnostic and is very portable and robust at the same time.</p>
<p>String.Concat on the other hand is raw speed. If you can get away with it, use it.</p>
<p>If you have a variable number of concatenations, then a StringBuilder is the way to go.</p>
<p>If you need to format strings and address internationalization issues, there&#8217;s nothing better than string.format.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Sumesh</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-455</link>
		<dc:creator>Sumesh</dc:creator>
		<pubDate>Tue, 16 Dec 2008 10:04:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-455</guid>
		<description>Is string.format() that nasty as stringbuilder.appendformat? CLR profiler shows it as best option in following case;


//;Way1

//string s1 = string.Format(&quot;Data Source={0}; Initial Catalog={1}&quot;, &quot;HA&quot;, &quot;HA&quot;);

//;Way2
//string s = &quot;Data Source=&quot;;
//s+=&quot;HA&quot;;
//s += &quot;Initial Catalog=&quot;;
//s += &quot;HA&quot;;

//;Way3
string[] pieces = new string[] {&quot;Data Source={0}; &quot;, &quot;Initial Catalog={1}&quot;, &quot;HA&quot;, &quot;HA&quot;};
string s1 = string.Concat(pieces);</description>
		<content:encoded><![CDATA[<p>Is string.format() that nasty as stringbuilder.appendformat? CLR profiler shows it as best option in following case;</p>
<p>//;Way1</p>
<p>//string s1 = string.Format(&#8221;Data Source={0}; Initial Catalog={1}&#8221;, &#8220;HA&#8221;, &#8220;HA&#8221;);</p>
<p>//;Way2<br />
//string s = &#8220;Data Source=&#8221;;<br />
//s+=&#8221;HA&#8221;;<br />
//s += &#8220;Initial Catalog=&#8221;;<br />
//s += &#8220;HA&#8221;;</p>
<p>//;Way3<br />
string[] pieces = new string[] {&#8221;Data Source={0}; &#8220;, &#8220;Initial Catalog={1}&#8221;, &#8220;HA&#8221;, &#8220;HA&#8221;};<br />
string s1 = string.Concat(pieces);</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Alan J</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-458</link>
		<dc:creator>Alan J</dc:creator>
		<pubDate>Mon, 13 Oct 2008 16:06:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-458</guid>
		<description>Just done a load of benchmarking from a time perspective on operation, variable, array, builder and format based concatenation and found the following &quot;rules&quot; (in relative terms since absolute is too situationally dependant):

- for a determinable end string length, the fastest method is the operation method (#1 above) for = 5

- for an undeterminable end string length, the fastest method is the operation method (#1 above) for = 7. However since dynamically sizing an array has it&#039;s own overhead, for almost all practical purposes a null instantiated string builder is more efficient

- string.format is an interesting case because it allows you to effectively concatenate fewer strings than you would have to using another method (cf. building a string to match the format &quot;a{0}b{1}c&quot;), practically though it&#039;s still the least efficient method for any situation where you aren&#039;t formatting about 7 fewer strings than a builder would concatenate. I can think of no situation where that could reasonably occur.

This essentially matches David and Jouni Heikniemi&#039;s findings: think about using stringbuilder at around 5-7 concats</description>
		<content:encoded><![CDATA[<p>Just done a load of benchmarking from a time perspective on operation, variable, array, builder and format based concatenation and found the following &#8220;rules&#8221; (in relative terms since absolute is too situationally dependant):</p>
<p>- for a determinable end string length, the fastest method is the operation method (#1 above) for = 5</p>
<p>- for an undeterminable end string length, the fastest method is the operation method (#1 above) for = 7. However since dynamically sizing an array has it&#8217;s own overhead, for almost all practical purposes a null instantiated string builder is more efficient</p>
<p>- string.format is an interesting case because it allows you to effectively concatenate fewer strings than you would have to using another method (cf. building a string to match the format &#8220;a{0}b{1}c&#8221;), practically though it&#8217;s still the least efficient method for any situation where you aren&#8217;t formatting about 7 fewer strings than a builder would concatenate. I can think of no situation where that could reasonably occur.</p>
<p>This essentially matches David and Jouni Heikniemi&#8217;s findings: think about using stringbuilder at around 5-7 concats</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: John C</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-454</link>
		<dc:creator>John C</dc:creator>
		<pubDate>Wed, 13 Feb 2008 15:00:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-454</guid>
		<description>Great article! Thanks. I knew about the differences between String and StringBuilder, but I&#039;m really impressed by the depth of the explanations. As for the StringBuilder.AppendFormat(), the mechanism is a big suprise to me.</description>
		<content:encoded><![CDATA[<p>Great article! Thanks. I knew about the differences between String and StringBuilder, but I&#8217;m really impressed by the depth of the explanations. As for the StringBuilder.AppendFormat(), the mechanism is a big suprise to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: bob scola</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-453</link>
		<dc:creator>bob scola</dc:creator>
		<pubDate>Wed, 05 Dec 2007 23:51:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-453</guid>
		<description>Your test case,  GetPlussedString(), is bogus. With it you have only discovered that the compiler is smart enough to pre-concatinate literals and consts, (which is great to know for code reviews) but it has nothing to do with runtime concatenating of strings. Therefore youâ€™ve learned nothing in GetPlussedString().  About GetPlussedString(), &quot;is about the most efficient way we can achieve&quot;.  No, as you havenâ€™t achieved anything, other than breaking up literals for readability in your source without incurring a performance penalty.  Perhaps if you had used actual string variables instead, you would have learned something from your first example.</description>
		<content:encoded><![CDATA[<p>Your test case,  GetPlussedString(), is bogus. With it you have only discovered that the compiler is smart enough to pre-concatinate literals and consts, (which is great to know for code reviews) but it has nothing to do with runtime concatenating of strings. Therefore youâ€™ve learned nothing in GetPlussedString().  About GetPlussedString(), &#8220;is about the most efficient way we can achieve&#8221;.  No, as you havenâ€™t achieved anything, other than breaking up literals for readability in your source without incurring a performance penalty.  Perhaps if you had used actual string variables instead, you would have learned something from your first example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Jose Delli Gatti</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-444</link>
		<dc:creator>Jose Delli Gatti</dc:creator>
		<pubDate>Tue, 25 Sep 2007 06:24:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-444</guid>
		<description>Hi,

I&#039;m really impressed by the depth of your research and the quality of this article.

It&#039;s clear and concise.

Thanks for the contribution!</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m really impressed by the depth of your research and the quality of this article.</p>
<p>It&#8217;s clear and concise.</p>
<p>Thanks for the contribution!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: David Cumps</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-449</link>
		<dc:creator>David Cumps</dc:creator>
		<pubDate>Fri, 21 Sep 2007 06:48:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-449</guid>
		<description>I used the CLR Profiler 2.0, a (free) tool from Microsoft. You can download it at:

http://www.microsoft.com/downloads/details.aspx?FamilyID=A362781C-3870-43BE-8926-862B40AA0CD0&amp;displaylang=en</description>
		<content:encoded><![CDATA[<p>I used the CLR Profiler 2.0, a (free) tool from Microsoft. You can download it at:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=A362781C-3870-43BE-8926-862B40AA0CD0&amp;displaylang=en" rel="nofollow">http://www.microsoft.com/downloads/details.aspx?FamilyID=A362781C-3870-43BE-8926-862B40AA0CD0&amp;displaylang=en</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Chinh Do</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-450</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Fri, 21 Sep 2007 03:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-450</guid>
		<description>Very informative and well researched article. I also did some research into StringBuilder vs &quot;+&quot; but this sheds much better light into the generated IL and memory usage.

By the way, what was the application you used to profile your test code and to produce those profiling charts? Chinh</description>
		<content:encoded><![CDATA[<p>Very informative and well researched article. I also did some research into StringBuilder vs &#8220;+&#8221; but this sheds much better light into the generated IL and memory usage.</p>
<p>By the way, what was the application you used to profile your test code and to produce those profiling charts? Chinh</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Bart</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-445</link>
		<dc:creator>Bart</dc:creator>
		<pubDate>Wed, 19 Sep 2007 03:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-445</guid>
		<description>Hi David,

I do have an older blog post on the use of StringBuilder at http://community.bartdesmet.net/blogs/bart/archive/2005/10/04/3583.aspx - it might be an interesting read as well. Notice it&#039;s written in a pre-.NET 2.0 manner without the use of the Stopwatch class to measure perf results.

-Bart</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>I do have an older blog post on the use of StringBuilder at <a href="http://community.bartdesmet.net/blogs/bart/archive/2005/10/04/3583.aspx" rel="nofollow">http://community.bartdesmet.net/blogs/bart/archive/2005/10/04/3583.aspx</a> &#8211; it might be an interesting read as well. Notice it&#8217;s written in a pre-.NET 2.0 manner without the use of the Stopwatch class to measure perf results.</p>
<p>-Bart</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: David Cumps</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-451</link>
		<dc:creator>David Cumps</dc:creator>
		<pubDate>Tue, 18 Sep 2007 08:39:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-451</guid>
		<description>If I remember correctly (not verified right now), doing: return &quot;String&quot; + var + &quot;string&quot;; will result in one String.Concat call under the hood (using the string, string, string overload).

Normally it&#039;ll do this till 4 string overloads before creating scenario 3 internally. (That&#039;s what I&#039;ve come to understand from the references on top of my article).</description>
		<content:encoded><![CDATA[<p>If I remember correctly (not verified right now), doing: return &#8220;String&#8221; + var + &#8220;string&#8221;; will result in one String.Concat call under the hood (using the string, string, string overload).</p>
<p>Normally it&#8217;ll do this till 4 string overloads before creating scenario 3 internally. (That&#8217;s what I&#8217;ve come to understand from the references on top of my article).</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Rick Strahl</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-452</link>
		<dc:creator>Rick Strahl</dc:creator>
		<pubDate>Mon, 17 Sep 2007 22:18:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-452</guid>
		<description>So what happens if you have a scenario 1 but instead you have a dynamic variable in the concats? I suppose that&#039;ll be the same as scenario 2 then?

As a general rule if I do 3-4 concats I tend to use + operators if only for readability. Antyhing more I use a StringBuilder.

While this stuff makes sense in real performance critical scenarios, I would consider this the sort of micro profiling that yields the least performance gains in most applications.</description>
		<content:encoded><![CDATA[<p>So what happens if you have a scenario 1 but instead you have a dynamic variable in the concats? I suppose that&#8217;ll be the same as scenario 2 then?</p>
<p>As a general rule if I do 3-4 concats I tend to use + operators if only for readability. Antyhing more I use a StringBuilder.</p>
<p>While this stuff makes sense in real performance critical scenarios, I would consider this the sort of micro profiling that yields the least performance gains in most applications.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: David Cumps</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-447</link>
		<dc:creator>David Cumps</dc:creator>
		<pubDate>Mon, 17 Sep 2007 20:45:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-447</guid>
		<description>I came to the same conclusion today Brandon, when having to concatenate strings, I thought by myself &#039;when would I ever be using the array overload?&#039;, and indeed, it&#039;ll be a very rare occurrence.

In the future I&#039;ll be using StringBuilder according to Jouni Heikniemi&#039;s guidelines.

Quoted:
&quot;If you have no idea on the resulting string size, use StringBuilder if you have at least 7 concatenations.

If you can roughly (with 30% accuracy) estimate the resulting string size, use StringBuilder if you have at least 5 concatenations.

If you can estimate the resulting string size with good accuracy, use StringBuilder if you have at least 3 concatenations.

Under no conditions is StringBuilder faster for less than 3 concatenations.

StringBuilder beats strings for 10+ concatenations in every practical situation.

The longer the strings are, the more final string size estimations will help you (but accuracy becomes more critical).&quot;

I&#039;ve also come to the conclusion that simply estimating the minimum size is a good start as well.

eg: I know I&#039;m going to be appending StackTraces, so the StringBuilder I&#039;m creating starts with an initial size of 256 or 512 (I&#039;m using those values since the StringBuilder has 16 as default and would always be doubling them, this I&#039;m saving out some initial doubling)</description>
		<content:encoded><![CDATA[<p>I came to the same conclusion today Brandon, when having to concatenate strings, I thought by myself &#8216;when would I ever be using the array overload?&#8217;, and indeed, it&#8217;ll be a very rare occurrence.</p>
<p>In the future I&#8217;ll be using StringBuilder according to Jouni Heikniemi&#8217;s guidelines.</p>
<p>Quoted:<br />
&#8220;If you have no idea on the resulting string size, use StringBuilder if you have at least 7 concatenations.</p>
<p>If you can roughly (with 30% accuracy) estimate the resulting string size, use StringBuilder if you have at least 5 concatenations.</p>
<p>If you can estimate the resulting string size with good accuracy, use StringBuilder if you have at least 3 concatenations.</p>
<p>Under no conditions is StringBuilder faster for less than 3 concatenations.</p>
<p>StringBuilder beats strings for 10+ concatenations in every practical situation.</p>
<p>The longer the strings are, the more final string size estimations will help you (but accuracy becomes more critical).&#8221;</p>
<p>I&#8217;ve also come to the conclusion that simply estimating the minimum size is a good start as well.</p>
<p>eg: I know I&#8217;m going to be appending StackTraces, so the StringBuilder I&#8217;m creating starts with an initial size of 256 or 512 (I&#8217;m using those values since the StringBuilder has 16 as default and would always be doubling them, this I&#8217;m saving out some initial doubling)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: Brandon Croft</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-446</link>
		<dc:creator>Brandon Croft</dc:creator>
		<pubDate>Mon, 17 Sep 2007 20:10:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-446</guid>
		<description>Reflecting String.Contact(String[]) reveals that internally, another array is allocated with the same length as the argument. The total size of the strings is summed and a new string is created with the actual length.

This means that two copies of your array would be allocated. I think this can be problematic for large arrays. The only benefit seems to be a pass whereby the final string size is known before final string allocation.

Contrast this with StringBuilder, where if you knew the approximate size of the resulting string, you could initialize the capacity to something large enough to hold it. Combine this with the fact that array concatenation would seem strange to me as a code reader and the solution becomes clear: Use a stringbuilder and guess the initial capacity. If you are unsure of the capacity, trace the actual length of your resulting strings and adjust.</description>
		<content:encoded><![CDATA[<p>Reflecting String.Contact(String[]) reveals that internally, another array is allocated with the same length as the argument. The total size of the strings is summed and a new string is created with the actual length.</p>
<p>This means that two copies of your array would be allocated. I think this can be problematic for large arrays. The only benefit seems to be a pass whereby the final string size is known before final string allocation.</p>
<p>Contrast this with StringBuilder, where if you knew the approximate size of the resulting string, you could initialize the capacity to something large enough to hold it. Combine this with the fact that array concatenation would seem strange to me as a code reader and the solution becomes clear: Use a stringbuilder and guess the initial capacity. If you are unsure of the capacity, trace the actual length of your resulting strings and adjust.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: GeekkFromIndia</title>
		<link>http://www.cumps.be/string-concatenation-vs-memory-allocation/comment-page-1/#comment-448</link>
		<dc:creator>GeekkFromIndia</dc:creator>
		<pubDate>Sun, 16 Sep 2007 20:16:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cumps.be/string-concatenation-vs-memory-allocation/#comment-448</guid>
		<description>Thanks David. This blog was really helpful.</description>
		<content:encoded><![CDATA[<p>Thanks David. This blog was really helpful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
