String object optimization in Framework 1.1 compared to 1.0

  • Thread starter Thread starter Oleg Sobol
  • Start date Start date
O

Oleg Sobol

Hi, all...

The question I have concerns string objects and how they are executed by
CLR. Based on an article written in 2002 (last updated Dec 2003)
http://www.codeproject.com/dotnet/strings.asp , it is more advisable to
use StringBuilder class than the String object to manipulate strings in
.Net because StringBuilder is more optimized. So, I was wondering if
there had been any optimizations made to String object in Framework 1.1,
and how it compares to StringBuilder? And also if there are more
optimizations on the way in 2005 version of the Framework?

Thanks in advance
Sincerely,
Oleg
 
Oleg Sobol said:
The question I have concerns string objects and how they are executed by
CLR. Based on an article written in 2002 (last updated Dec 2003)
http://www.codeproject.com/dotnet/strings.asp , it is more advisable to
use StringBuilder class than the String object to manipulate strings in
Net because StringBuilder is more optimized. So, I was wondering if
there had been any optimizations made to String object in Framework 1.1,
and how it compares to StringBuilder? And also if there are more
optimizations on the way in 2005 version of the Framework?

It's not so much because StringBuilder is optimised as because using a
StringBuilder means you don't have to create as many strings. It tends
to be handy if you're concatenating more than about 5-10 times (as
lower than that, the "effort" of creating the StringBuilder outweighs
the creation of the extra strings - although of course it depends on
exactly your situation.

I'm not sure that StringBuilder is actually handled particularly
differently by the CLR/JIT, btw - the reason it can modify strings is
because it's in mscorlib, so has access to the internal methods of
string which can modify it.
 
Back
Top