Colin Thomsen's Microsoft Blog

I'm a developer working on the code profiler that ships with Visual Studio 2010 Premium and Ultimate editions. At a previous company I worked on computer vision software for face and gaze tracking.

July, 2007

Posts
  • Colin Thomsen's Microsoft Blog

    Visual Studio 2008, Beta 2 (now with some of my code)

    • 0 Comments

    Today we released Beta 2 of VS2008. This is the first public release from Microsoft that contains a nontrivial amount of code that I wrote (even though I haven't written too much code just yet). I had barely synched up the source tree and only fixed a couple of bugs when we released Beta 1 but now I've found my feet and am contributing more.

    The major release announcements have focussed on the flashier (and admittedly very cool) aspects of the Beta like LINQ and some of the HTML editing and Javascript debugging features. However, us Profiler folks have also been toiling away adding new features and fixing bugs. Look out for things like (and some of these already featured in Beta 1, but they just keep getting better):

    • A promotion to the new Developer menu
       dev_menu
    • Hot path - find the critical path/paths through your call trees
      hotpath
    • Noise reduction - trim and/or fold your call trees so that they are easier to examine. See above for folding example.
    • Comparison reports - compare subsequent profiler runs to determine if code changes are improving performance
      comparison_reps
    • x64 OS support - profile on x64 Vista or W2K3 server 

    If you can, please download it and let us know what you think. If you don't have the time at least take a look at the overview video showing some of the major features. You should also check out Ian's entry about controlling data collection while profiling. Hopefully I'll have time to go through some of the new profiler-specific features soon.

  • Colin Thomsen's Microsoft Blog

    C# for C++ Devs: Generics vs Templates for Primitive Types

    • 3 Comments

    I was trying to write some type-generic (almost) code in C# using a pattern that I commonly use in C++. A very simple version of what I was trying to do looks something like:

    class B
    {};

    template<typename T>

    int convert(T value)

    {

        return (int)value;

    }

     

    int main(int argc, char* argv[])

    {

        convert(3.5f);

        convert(11.5);

        // The line below would fail with "error C2440: 'type cast' : cannot convert from 'B' to 'int'"

        //convert(B());

        return 0;

    }

    In C++ this compiles and runs just fine, as long as you don't uncomment the convert function for the class. For templates, code is only generated when needed at compile time and as long as the substituted code supports the required functions (or in this case cast), everything is just fine.

    The equivalent C# program using generics looks like this:

    class Program

    {

       static int convert<T>(T value)

       {

          return (int)value;

       }

     

       static void Main(string[] args)

       {

          convert(11.5);

       }

    }

    Unfortunately it doesn't compile. I get an error: Cannot convert type 'T' to 'int'

    This is due to the way generics are handled in C#. Instead of having code generated for different types at compile time, generics are resolved to the particular type at runtime (JIT actually). This means that the convert function shown above must support all types at compile time. This is not the case, since generic objects cannot always be converted to integers.

    It is possible to use constraints if you are not using a primitive type, but there doesn't seem to be a nice way to support 'generic across primitive types' in C#. Am I missing something?

Page 1 of 1 (2 items)