22 February 2012

Common Type System (CTS)



In order to manage different data types for inter language operability Microsoft provide special language called Microsoft IL( Intermediate language). With the help of IL we can combine different languages for one application. We can disassemble the IL code with the command ILDASM. Il file created when we compile the program. For clear more go through the figure bellow

The figure explains that in VB the data type integer compiled with the complier vbc.exe and in the C# the data type int compiled with the compiler csc.exe and form an intermediate code system.Int32 in inter mediate language. That is Integer in VB and int in C# is same as system.Int32 in IL. With the help of IL inter language operability is possible.
Consider the figure bellow which explain the compilation process of .net source code

 

Don’t mix .exe and .dll file with actual system files. It is not exactly like that, it is .net frame work’s .exe and .dll file. That means this dll and exe need CLR to run and in the case of dll there is no need of registry registration as windows dll for using. From that itself it is clear that dll is not exactly like conventional dll.
.Net module
.dll is highly resource consumable. So we depend on another technology called .net module to represent the intermediate code in IL. That means it is a temporary code for helping the smooth linking and running of a program that use multiple languages to produce a single product. .exe,.dll,.Net modules are file types and IL is a language format designed by Microsoft.
.Net Assembly
            The file types .exe,.dll,.Net module are not conventional file types in OS. So they need CLR to run the files. The file types in IL together are called .Net assembly.
Exception Manager
            It is familiar to us, exception manager is to manage exceptions when executing a program as in java .
COM Marshallar
            The code that can be run under the CLR is managed code. Some times we can not use the code supported by CLR. That means we may use conventional dll files for some applications. Those types of code are called unmanaged codes. That is some codes by pass the CLR, They are unmanaged codes. The COM Marshallar is used for marshalling of data between managed code and unmanaged code. In short COM Marshallar is used to use the code that not supported by .net together with the code supported by .net frame work.
JIT Compiler
            JIT compiler means Just In Time compiler. In the above figure native code is generated by JIT compiler. That is the function of JIT compiler. JIT compiler is not a compiles as its name indicates. It is used to convert a code to system specific code or native code, native code are CPU specific. In short JIT Compiler is used to produce architectural compactable code. Architecture of machines are varies from machine to machine, we can generate architectural compactable code with the help of JIT Compiler for achieving maximum performance.
Ngen.exe
            It is used to create native codes forcefully

IBM compactable pc architecture




The above figure represents the IBM compactable pc architecture. We can clearly identify from the figure that there are mainly two areas stack and heap. The stack area is again divided in to two parts as shown in figure. They   are  member variables area or private area, and member function area or public area . The heap contains the global variable and static variables.
                                    In stack area public interaction is very less.  That is we cannot access the stack area directly without the help of objects. The heap area is the area where high public interactions occurs because of this we write all the programs with static main and that lies in heap area.
All the main( ) function lies in the heap area because we defined it as static. In the figure we can see a barrier between heap area and stack area, that means we can’t access the stack area directly. Os initiate the program in heap area as shown in figure. But we can’t go to stack area. For accessing stack area member functions we need the help of objects. Here come the duty of objects; the real definition or function of object is that to make accessible the stack area. Through objects we can access only member functions and with the help of member functions we can access the member variables too.  The static main( ) functions are lies in heap area but if we define a function without static key word it lies in stack area and we or os cannot access it directly. This makes our program error. We want to go through some codes for understand the above more clearly. All the codes I use in these tutorials are C# codes.
[Code]
Using system;
Class sample {
            Public static void main ( ) {
                        int x,y,s=0;
                        X=5;
                        Y=20;
                        S= sum(x,y);
                        System .console.writeline(“sum=”+s);
            }
public int sum(int x, int y){
                        return(x+y);
}
}
[/code]
            Is there any problem in the above code?. If u understands the above explained architecture or you have much experience in programming you can find the error of previous program within seconds. There is a compilation error in the above program. Before going to the error I would like to tell something. This is a console application program. You can see the console.write line statement there and the ‘+’ operator is used as a concatenate operator in C#. Come to the error back, this mistake is actually architectural mistake. I’ll give two alternatives to this program from those you can understand what error occurred and what is the reason for that ok?.
1
[Code]
Using system;
Class sample {
            Public static void main ( ) {
                        int x,y,s=0;
                        X=5;
                        Y=20;
                        sample sa=new sample( );
                        s=sa.sum(x,y);
                        System .Console.Writeline(“sum=”+s);
            }
public int sum(int x, int y){
                        return(x+y);
}
}
[/code]
2
[Code]
Using system;
Class sample {
            Public static void main ( ) {
                        int x,y,s=0;
                        X=5;
                        Y=20;
                        s=sum(x,y);
                        System .Console.Writeline(“sum=”+s);
            }
Public static int sum(int x, int y){
                        return(x+y);
}
}
[/code]
I hope you got the reason from the above codes. Don’t worry who didn’t get the reason even reading the above codes. I’ll explain for you people.
Look at our architecture figure once more that picture. Put the picture in your mind we need that ok?. In first code(the code with problem),  what is happening there what is the problem there. In the line 7 s=sum(x,y); how this statement work?. The function sum can’t accessed there because see the picture member functions are in stack area. Can u access that?. With the help of an object you can access that that is shown in code 1 and please don’t follow the second one it is not the actual method. The second one I give to u to explain the architecture. What happened in second one? The function is declared as static so it lies in heap area so we can access it anywhere from the program because it has the global scope. I hope it is clear for all. We here define object as, the object is the authorized entity or member to access the stack area from heap area. I think u all got a clear idea about objet and the fog on the object is wiped from your mind.
All most all programming languages support public static void main( ) because of security reason. As I said before the second method is not perfect and it is not preferable. It is not a good method to practice it is less secure and not a good programming concept. For programs the start up will be in heap area then access the stack. I’ll give a code to u please do it before do it in system go through it and analyze it. After analyzing come to a conclusion whether it works or not?

Work
[Code]
Using system;
Class sample {
            Public static void main ( ) {
                        int x,y,s=0;
                        X=5;
                        Y=20;
                        sample sa=new sample( );
                        s=sa.sum(x,y);
                        System .Console.Writeline(“sum=”+s);
            }
public int sum(int x, int y){
            show( );
                        return(x+y);
}
public void show( ){
                        Console.Writeline(“Hai”);
}

}
[/code]