StringBuilder Vs String

G

Guest

Hello Friends,

I know this question is not specific to .NET CF but as we are in the land of
less memory, I want to ask this question to all your techies. Its strange
thought in my mind.

we often hear that its adivsable to use StringBuilder when to many string
manipulations are there.
For example
Dim str1 as string
str1 &= "Viral"
str1 &= "Thakkar"

ok fine, but what about this case

---Dim str1 as string = "Viral" & "Thakkar"---
Is it still advisable to use stringbuilder, i mean in above case also it
will create two object.. bla bla bla?

thanks,
Viral
 
G

Guest

For just 2 or 3 concatenations, a StringBuilder probably is slower than just
concatenating as you still have to create the object. When you get to say 4
or more, then the StringBuilder starts making sense.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
G

Guest

I was once at a contract that was very concerned with performance and we ran
a test using string concat and string builder. We found that for operations
of up to 10 concats it was more efficient to use string concats but more than
about 10 string builder was more efficient. We also found that when we were
memory constrained that preallocating the string buffer was always more
memory efficient.

Rick D.
Contractor
 
G

Guest

Did you find out why it was more efficient to use string concats over string
builder for less than 10 operations?

Preallocating memory has always been more efficient. Historically this is
the way it always was with languages such as COBOL and Fortran. It's only
newer languages (OO mainly) that had recently (20 yrs or so) has introduced
variable length types, I think Smalltalk 67 was the first? In the bad old
days you had to specify how much memory you needed and allocate it.
 

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

Top