Question about string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Bruce,

Can you please explain me how compiler would be able to optimize "+" for the
below code?

The reason why I did not want to use string concatenation was that I wanted
it to be a single string object in an effort to reduce memory consumption.
But if I use "+" does not that consume more memory due to string's inherent
property of
immutability and heavy cost of concatenations?

Please correct me if I am wrong...
 
Hi,

why don't you want to use stringbuilder?

Regards

Daniel
 
Peter said:
Tests have shown that StringBuilder is more efficient on
concatenation of at least 7 or more parts.
Peter

You should really be using the StringBuilder for all string concatenation.
If your site is under load, you can see a substantial increase in memory due
to strings even when concatenating few strings. We see this issue pretty
often.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.
 
Peter said:
Jim,
I would be reluctant to accept a blanket statement such as this.
Stringbuilder is *NOT* always faster / more efficient for string
concatenation.

Read two resources (there are others):

http://geekswithblogs.net/johnsperfblog/archive/2005/05/27.aspx

http://www.heikniemi.net/hc/archives/000124.html

Thanks, Peter. I'm aware of these and other such comments. Perhaps the scope
of my statement was too broad. I should have said that you should *almost*
always use SB, but note that I'm not talking about performance here. I'm
talking about the large number of enterprise applications that I have seen
that struggle with memory issues because of reading articles just such as
you've outlined here.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry:
Getting the PID and TID of a COM Call

Describes how to get the PID of the
dllhost process a COM call is executing
in and how to locate the thread as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top