ValueType virtual methods and why avoid them

August 19, 2007

I've just stumbled upon Marc Brooks' interesting post explaining and comparing value types and reference types. One of the points Marc makes is that any value type you'd write (i.e. a C# struct) would inherit from System.ValueType an implementation of the Equals and GetHashCode methods, with a default behavior suited for value types.  That is, a behavior that compares the fields of the value type to determine equality or to calculate a hash code. A critically important point that must be mentioned here is that ValueType.Equals and ValueType.GetHashCode come with an enormous performance penalty.  Consider the following code: struct MyValueType {public...
2 comments

JIT Optimizations, Inlining, and Interface Method Dispatching (Part 2 of N)

August 12, 2007

Not a full-blown post again, but just a couple of notes to give myself some (though not all) closure regarding the subjects brought up in the first part. First of all, I've bothered to check with VB.NET (those of you who haven't tried it, really should... the cuteness of writing something like Public NotOverridable Overrides Sub Foo() is overwhelming).  The VB.NET compiler produces the same IL we have seen in the first part, i.e. the same IL the C# compiler produces, for both interesting scenarios: dispatching a virtual method on a statically known sealed type, and emitting the callvirt opcode...
2 comments

Debugging and Investigation Tools

August 11, 2007

As part of the Windows Internals course I am teaching for Sela, I have compiled a list of tools that we are using throughout the course for demonstrations, and that I am recommending to students to use in their daily debugging and investigation needs. In this post, I will introduce you to some of these tools, which I use on a regular basis.  Please note that I don't own any of these, and (most of them) are freely distributed on the web.  For more information, you are more than welcome to contact the tool authors. Process Explorer, Sysinternals (Microsoft) Process...
2 comments