Thursday, November 26, 2015

What is CLR, CTS, CLS in .NET ?

A Brief Introduction To IL code, CLR, CTS, CLS and JIT In .NET


Before explaining these terminologies, I would like to explain how .NET code gets compiled. The developer writes source code in any .NET language i.e. it may VB.NET or C# or VC+++.NET, etc. The source code is compiled to Intermediate code known as IL code by the respective compilers for example for C# it is csc.exe compiler, for VB.NET it is vbc.exe compiler, etc. This half compiled code is then given to JIT(just in time compiler) by CLR which converts IL code to machine specific instructions which then gets executed. In this way a .NET code gets compiled. For better understanding have a look to following diagram :
IC15013
Now we ll have a close look to above terminologies one by one. We will start from IL code.
  • IL Code : The word IL Code stands for Intermediate Language Code. It is a CPU independent partially compiled code. When we develop our .NET  application, we don’t know in what kind of environment our code will run i.e. on which operating system it will be finally hosted, what will be the CPU configuration, etc. So for this purpose we have IL code which is compiled according to machine configuration. IL code is given by Language compiler which is different for different languages for example csc.exe compiler for C#, vbc.exe compiler for VB.NET, etc.
  • CLR : CLR stands for Common Language Runtime. It is the heart of our .NET Framework. CLR performs following tasks :
  1. Garbage Collection : When we run our .NET application, many objects are created. Garbage collection is a background process which deletes the objects which are not in use by the application and frees memory.
  2. Code Access Security(CAS) and Code Verification(CV) : CLR checks the whether the code has access rights and it is safe and authenticated to be used.
  3. IL to Native Translation : The main task of CLR is to provide IL code to JIT to ensure that code is fully compiled as per machine specification.
  • CTS : CTS stands for Common Types System. In .NET we have various languages like C#, VB.NET, etc. There may be many situations where we want code written in one language to be used in another. In order to ensure that we have a smooth communication between different languages, we have CTS. CTS ensures that datatypes defined in two different languages get compiled to a common data type so that code written in one language can be used by another.
  • CLS : CLS stands for Common Language Specifications. It is a subset of CTS. CLS is a set of rules or guidelines which if followed ensures that code written in one .NET language can be used by another .NET language. For example one rule is that we cannot have member functions with same name with case difference only i.e we should not have add() and Add(). This may work in C# because it is case-sensitive but if try to use that C# code in VB.NET, it is not possible because VB.NET is not case-sensitive.
  • JIT : JIT stands for Just In Timer Compiler. It is the internal compiler of .NET which takes IL code from CLR and executes it to machine specific instructions.

Reference from : Link

No comments:

Post a Comment

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.