Archive for December 2001

 
 

Windows Forms and Themes

Windows XP supports skins. One can basically change how windows and standard controls are drawn. For example, here is WordPad running on my box with the Mac OS X theme:

WordPad using the OS X Theme for Windows XP

(FYI: OS X is much prettier than Windows, but native Windows themes have much better contrast and are more functional.)

However, if you develop a new Windows application using Visual Studio.NET and Windows Forms, your app will not respect the themes. You may set a button’s FlatStyle property to System, but your button will still draw as a plain old ugly Windows button.

What’s the trick? It seems that you must create a manifest file for your app, and in that manifest bind your app to COMCTL6. The details can be found at this page:

http://www.gotdotnet.com/team/windowsforms/Themes.aspx

Happy New Year!

.NET Garbage Collector Speed

I did some tests earlier today in order to find out how fast is the .NET garbage collector. I wrote a program that simply creates and then discards 100 million objects on the heap, in three different versions:

  1. One that manually frees objects.
  2. One that uses the Managed C++ garbage collector.
  3. One that uses thread-local allocator and manually frees objects.

The results are:

Manual freeing of objects 136 seconds
Garbage collected 136 seconds
Thread local allocator manual freeing 47 seconds

What can we learn for this? First of all, for most applications memory management is not going to be a bottleneck if the system can handle 100 million objects in a little over two minutes.

Second, garbage collection in .NET is as fast as manual memory management. (It does take up more memory, though.)

Finally, manual memory management without the synchronization overhead is roughly three times faster than the other two alternatives. If memory management proves to be an overhead, see if you can use a thread-local allocator.