Scott Hanselman

StringBuilders vs. String Concatenation

November 8, '03 Comments [0] Posted in Programming
Sponsored By

Some folks have said (you've heard them in the halls), “Oh ya, you should NEVER use String Concatenation, dude, use StringBuilder...ALWAYS.  Totally.”

Rico weighs in on this, and he's right on (emphasis mine):

I tend to give advice like "Many users find Stringbuilders useful for their concatenation pattens, consider using them and measure to see if they help you".  Wussy but safe :)

Big string -> small appends
It's substantially likely that appends will fit in the slop and so they're fast, this is the best case (buffer size becomes double the string when it no longer fits so on average the slop is half the current string length) (if there are lots of small appends to a big string you win the most using stringbuilder)

Big string -> big appends
While the string is comparable in size (or smaller) to the appends stringbuilder won't save you much, if this continues to the point where the appends are small compared to the accumlated string you're in the good case

Small string -> big appends
bad case, string builder will just slow you down until enough slop has built up to hold those appends, you move to "big string big appends" as you append and finally to "big string small appends" if/when the buffer becomes collossal

Small string -> small appends
could be ok if you had a good idea how big your string was going to get and preallocated enough so that you have sufficient slop for the appends. You might be able to do better if you just concated all the small appends together in one operation.

It's very hard to say which is faster/smaller in general... it's all about the usage pattern. [Rico Mariani]

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Measure twice, cut once...CLR Profiler 2.0

November 8, '03 Comments [0] Posted in Programming | Tools
Sponsored By

I see from Jan Gray's blog that the CLR Profiler (now 2.0) distribution has been updated.  You can  download CLR Profiler 2.0 here.  It just keeps getting better.  Kudos to Peter Sollich, the author.

We've just updated the CLRProfiler distribution. Once again, we're shipping both the source and the prebuilt binaries, and this time we're delighted to include a terrific ~100 page tutorial and reference manual written by the tool's author, Peter Sollich.

I think this new documentation greatly enhances the power and utility of the profiler by demonstrating how to use its features more effectively -- for example, how to diagnose a memory leak. [Jan Gray]

If you've been writing .NET code willy-nilly for the last few years and haven't profiled, try it.  There are lots of “for $” profilers out there, but this one (in previous versions) have helped us find memory leaks and all sorts of other weirdness. 

Also, familiarize yourself with Gregor Noriskin's article on MSDN: “Writing High-Performance Managed Applications : A Primer.”  He discusses the CLRProfiler and oodles of other good things.  His MSDN TV show on Code Optimization is also good.  Additionally Jan and Rico Mariani have a site up on GotDotNet dedicated to Managed Code Performance.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Learning to Love WSDL - Christian Weyer supports "Contract First"

November 7, '03 Comments [0] Posted in Web Services | ASP.NET | TechEd | Speaking
Sponsored By

Christian Weyer (Who? You mean THE Christian Weyer? Yes, THAT Christian Weyer) has made WSDL and VS.NET get along better with his Contract First VS.NET Add-In.

I talked about this in my TechEd: Learning to Love WSDL presentation (which is apparently still up at http://microsoft.sitestream.com/DEV/DEV389_files/default.htm) and many folks smarter than I have said the same thing. 

One of the things that's slick about Christian's imp is that he used his DynWSLib library and handles external schema imports better than the usually obtuse WSDL.EXE.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

My quest for the ultimate TabletPC

November 7, '03 Comments [0] Posted in Musings
Sponsored By

Matthieu Guyonnet-Duluc wrote me to tell me that a french Geek Site (apparently Geek is Geek everywhere) has a story on a mysterious Toshiba TabletPC M200 [Spéculations et vérités sur le M200 de Toshiba].  Use the Fish if you want to translate it to English, or ask Rory what it says.

Here's the juicy parts of a my lousy translation.  Note this strange news that doesn't jive with my previous scoop about Video RAM.  If this is true, it sucks, and I wonder if it's a heat thing?  I wonder if the Avalon team reads this and has a comment?

Can anyone confirm the release date on this baby?

...you know that Toshiba will leave its new generation TabletPC...used by Bill Gates to show OneNote 2003...

...a little more about the specifications of this Portegé M200...

- have a range of significant power in this model...
- the resolution would seem to be SXGA+ compared with the traditional XGA . In fact the two resolutions are announced in rumour on the Web also it is difficult to have an idea
- the 80 Gb will be with 5400 RPM, while the 60 Gb will be with 7200 RPM
- the video is a nVIDIA last generation with only 32 Mb of Video RAM  -the model with 128 Mb was a non-marketed prototype (Scott: bad news for Longhorn?)
- hardware button to automatically to launch OneNote
- the battery of almost 4 hours
- the bluetooth seems to be integrated
- a Secure Digital Slot

CPU - 1.4/1.5/1.6/1.7/1.8GHz
Memory - DDR333 256mb-2gb
LCD - 12.1"TFT SXGA+
Video - Ext. nVIDIA Map34-32/32MB
HDD - 40, 60, 80GB (5400rpm) 60GB (7200rpm) (Scott: Definitely the 60GB)
Ports - 2xUSB2.0, FIR, RGB, Mic, H.Phone, Rj-45, Rj-11
Communication - V.90/92 + Ethernet(10/100) + 802.11b, 11ab, 11g, 11ag + BT
Battery life - 3.9H W/Primary(4400mAh)
Dimension - 295x239x36(MAX)mm - TBD
Weight - 2kg (Scott: oy!)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Today's Minor Complaint...

November 6, '03 Comments [5] Posted in XML
Sponsored By

Why is this OK:

using (StringReader sr = new StringReader(response))
{
   try
   {
      retVal = xs.Deserialize(sr);
   }
    //yada yada yada

}

Why and this isnt?

using (XmlTextReader xr = new XmlTextReader(new StringReader(response), /*...yada yada...*/)
{
   try
   {
      retVal = xs.Deserialize(sr);
   }
    //yada yada yada

}

Because StringReaders derive from System.IO.TextReader which implements IDisposable and that's what the using keywords cares about.  XmlTextReader derives from the abstract XmlReader, and noone implements IDisposable. I suppose this has something to do with closing streams in the right order, blah blah.  Either way, it was a minor sadness today.

Poop.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.