Wednesday, October 31, 2007

C# Optimizing Compiler

Let me share nice thing that I noticed about C# compilation model. What I did was, I created a small program to print an Int32 array to console. Then I went into IL and checked out various function calls that C# compiler has made. There was one nice thing that I noticed. C# compiler sometimes optimizes your code by itself. Let me show you,

using System;

namespace Optimization


class Program

static void Main(string[] args)
Int32[] arr ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,11 };
for (Int32 i = 0; i<=arr.Length-1;i++) {




This is the code that I wrote to print a simple Int32 array. Below is the IL generated by this code snippet.

Compiler stores the array length in line IL_0000. The you can see there is no call to Array.Length property [internally it will call the method get_Length()] which I have used in For loop. Only calls that C# compiler added were to Initialize array, WriteLine() and ReadLine(). C# compiler have optimized our code internally so that there is no need to call Length with every loop iteration. It uses the length that is stored in the beginning to provide a performance boost. So, if you are doing such thing in your code, don't complicate things by declaring a variable just before the for loop just to store array length and use that variable in loop condition. You will be doing that to improve your application's performance but doing such heroics is not needed in this scenario.

I have just started to read about internals and currently I am dating HTTPSys driver :). I hope to get this done by November 2nd week.
Currently listening To: SHAGGY Feat. AKON - What's Love
...nJoy CoDiNg...

Tuesday, October 2, 2007

MS Office - One click blog publishing

Hey! guys, do you know how I created this blog entry. I simply wrote some stuff in my new MS Word 2007 and published it with one mouse click to my web blog. It's so damm easy, you only have to set up connection with your blog space provider and your blog account with your MS Word. From then onwards you can just write any content offline and publish it using new utility menu in office 2007. Information given bel;ow is just may be useless to most of you, but this just another document that I prepared long ago. You tend to forget things if you dont use them often :). Take a look at the menu screen shot above:
  • XML
    • Introduction
      • XML vs. HTML
        • xml describe data
        • xml focus on data
        • html display data
        • html focus on how data looks
      • XML
        • Extensible markup language
        • Define your own tags
        • DTD or XML Schema to describe data
      • W3C recommendation