February 2004 - Posts

"Java Beats .NET for Processing XML" ???!

All of you must have read about the recent benchmarking results from Sun on the XML processing performance difference between .NET and Java. If you have not yet read that then go here or here first ! Also here's a whitepaper from Sun on the performance of the SAX parser over the .NET pull parser.

I don't really know how far the facts stated are true but is there any other benchmarks that prove the same or otherwise ?! I personally haven't tried out finding the performance difference between doing XML parsing in .NET and Java but i am sure many other curious minds out there must have. So if you did, then it would be great if you can share your experience.

Also i was wondering why folks from MS haven't tried to state anything about this ?! Does the silence mean the acknowledgement of the results of the benchmarking ? I am skeptical about this and of course i have my own views about the whole 'Benchmarking for marketing' concept as such but will post about that in detail later.

.NET Riddle Redux - The Answer

hmm... I see only Steve attempted to find out the answer to the question; the riddle i posted earlier !

Ok here it is again.

Question : What is the only Type in .NET which has only a non-public constructor and the method body of which throws an exception when invoked ? If so then how is this particular Type instance ever gonna get created ?

Answer :  The Type in focus is the internal sealed Type - System.RuntimeType. The only way you can even try to instantiate this, is using Reflection, because the only constructor available is internal. But then again as i said earlier, the constructor would promptly throw you a NotImplementedException saying that the particular Type instance cannot be created ! hmm now ain't that a googly ?

As Steve said, there is magic that goes on in the background, weilded by the CLR Runtime all the while. Ok let me give you a little background on how i arrived at this particular discovery. Now before seeing this particularly weird thing, i was sure that you could serialize a Type information ( System.Type ) or rather the Type metadata somehow so that incase if say in a service someone wanted to create an instance of a particular Type, then he could create the object, serialize it along with the Type information which would mean that whoever would consume the serialized representation can now have both the Type metadata and the object instance of the Type too on the other end. <Rant>I know it sounds weird and strange and cranky ( whoa ) but these thoughts are what led me to this. </Rant>

Now the problem of trying to serialize the Type is that when you call Object.GetType(), it internally calls the FastGetExistingType() or InternalGetType(), unmanaged C++ methods which takes care of finding out the exact Type information of the most derived object instance and returns the System.RuntimeType which represents the Type in question. So even if we try to serialize the data, we will be serializing only the RuntimeType instance and not the exactly the System.Type instance. (Ain't that cool, the Runtime can deceive :) ) I even serialized the RuntimeType instance which i get from GetType() ( dont ask me how yet ), but i was not able to create an instance of the RuntimeType again because it kept throwing me an exception... Here's where it all started ..

Reflector came to the rescue and i started digging into RuntimeType. It was throwing an exception in the method body of the only non-public non-static constructor (internal) available. Any Object in the CLR sense, as far as i could figure out is the combination of Object.H, Object.CPP and Object.CS. Now the Runtime somehow handles the object instance and creates a handle, RuntimeTypeHandle, a pointer to the COR_EE struct of the object which will have the Type metadata in memory. The RuntimeType returned from GetType() call is basically a managed pointer to this memory location.

Basically, i went further on debugging the Rotor source code but then got completely lost when the realm of the CLR starts blurring and bleeding its boundaries into the unmanaged side ... hmm this is where i would like people from MS to extend a helping hand and explain the exact Type allocation, object initialialization and other stuff ! I definitely think that is a reasonable request to ask from the creators of the runtime right ?!

PS : Ok i could have confused things a bit here but i think you can get the picture !

<Frustration>aarghh, why cant people read minds ??</Frustration>

Link Interface 23.

Bumped onto a good bunch of articles ...

Hopefully this will keep you occupied for the weekend :)

Snippet : IsSoftwareInstalled Check.

Saw this quickie snippet to find out if a particular software is installed on your system. Well check out the code and you'll get the idea ..
 
This particular snippet sniffs out whether MS Word is installed or not !
 
using Microsoft.Win32 ;
 
Class WordTest
{
     public static bool IsWordInstalled()
     {
          bool res;
 
          // define the RegistryKey objects for the registry hives.
          RegistryKey regClasses = Registry.ClassesRoot;
 
          // check whether Microsoft Word is installed on this computer,
          // by searching the HKEY_CLASSES_ROOT\Word.Application key.
          RegistryKey regWord = regClasses.OpenSubKey("Word.Application");
 
          if ( regWord == null )
               res = false;
          else
               res = true;
 
          // always close Registry keys after using them.
          regWord.Close();
 
          return res;
     }
}

A .NET Riddle.

A riddle of small stature but .NET nonetheless ...

I was looking deep into the Rotor source code yesterday and came across this really weirdo thing which sent those shock waves up the grey cells ... A really strange phenomena has been occurring right under all our noses and many didn't know what it was. So i decided to post about it and for fun make it as a riddle instead of an informative post ( dont curse me yet !). I did debug Rotor to its roots to find out the internal working but i know that i would definitely not be able to express the details anywhere close to what could be explained by folks back at the big house. Here it is.

What is the only Type in .NET which has only a non-public constructor and the method body of which throws up a NotImplemented Exception. If so how is the type instance created then ?

Clue : This is what i would like to call a 'Blackhole Riddle' ! One that sucks the answer right within the question ... Come on. Are you expecting more ?

The answer is pretty simple though once you think about it but it came as a huge blow to me when i saw the implementation of it while going through the Rotor souce. Anyone who has been even mildly curious about the internal working of the CLR can answer this. Pour in your answers.

I do have a request too. I was wondering whether is there any request based blog discussion somewhere in MSDN blogs ? I know Chris once had a Request a Topic blog post but other than that everyone seems to be interested in what's coming up in the future, Whidbey, Orcas and Longhorn. I will be happy if the leads at MS or anyone who knows the stuff can explain the bits, this riddle relates to and keep doing so until most of the low level principles are even superfluously covered ... Or if that is a very unreasonable request to ask then tell me why ?!

MVPs but not in MS Technologies.

We have heard many Most Valuable Professionals(MVP) in .NET or rather in many Microsoft Technologies ... There was recent talk on why other technologies and companies ( hmm dont remember who exactly ... ) fail to recognize their valuable developers and do something similar.

I think there's a list out for top 50 MVPs in the Enterprise Java world. Kewl ! Also there is a list of top contributors according to Carloz Perez here ...

Link Interface 22.

Worthy articles and sites to squander some more of your time ...

  • Anders talks about CLR Design Choices ... and in case you've missed, check out the other interviews also.
  • Java vs .NET Security Part III via Serverside.NET
  • Why dont i use C# by Christopher Diggins - A definitely must read. He talks about certain subtle features but then in my opinion, most of his points are related to the whole of CLR as such and not C# specifically.
  • Mixing and Matching: Using STL with the Base Class Library - A decent starter if you are using STL and Generics from Whidbey. But i think the author might be wrong on STL being the first choice. I am not sure how STL has been implemented to be compiled as IL, but when you try to compare 1) compile time STL generics and 2) run-time generics in whidbey, my guess would be that Generics will stand ahead in terms of performance. Also, i think, Generics syntax looks much more neater than STL. hmm any opinions on that ?
  • Found a great blog via Mahesh. Ravi Mohan from ThoughtWorks, India where Fowler works, has a blog .. Dont ask me where the subscription feed is :( Also you would want to check out his friend's sites : DistributedXP.com hosted by Amit Rathore, Rajesh Babu.
  • Chris has a new post on Apartments and Pumping in the CLR... As of usual, most of the things went over my head .. Need to do another reading or two soon ..
  • A good article comparing Object-oriented technologies as used today to Service oriented loosely coupled designs for the future. Read Horses for Courses: Services, Objects, and Loose Coupling - Integration without compromise. But i have my opinions on closely or directly comparing Webservices as such to Service oriented architecture ...

Console Support.

I saw this recent post by Wesner Moise and realized that i had posted about the lack of such Console features quite some time ago !

All i wanted was ClearScreen back then but the features that Wes explains seem much more than that :) You have events propagated based on user actions, ability to set Buffer size of the console window, cursor control and much more ..

Wes, i missed your article back when i wanted it, but instead found this in C# Corner. Solved my problems for then but will check out your code too now :)