Friday 5 February 2016

CLR Features and Benefits

CLR Features and Benefits

Common Language Runtime is a heart of the .net framework. It actually manages the code during Execution. The Code that runs under the CLR is called “Managed Code”. The code that is executed under .net runtime gets benefits like cross language inheritance, cross language exception handling, enhanced Security, Versioning and development support, a simplified model for component interaction, debugging and Profiling services.
CLR Managed Code Execution Process
  • The Process of Compiling and executing managed code is given below
    When you compile a program written in any of language that target CLR., the compiler translate it into Microsoft Intermediate Language (MSIL) or Intermediate Language (IL). It does not depend on Language and always get translated to IL, This ensures language Interoperability.
  • In addition to translating the code into IL, Compiler also produces metadata about the program during the process of compilation. Metadata contains the description of the program such as Classes and interfaces, the dependencies etc.
  • The IL and the metadata are linked in an assembly.
  • The Compiler creates .EXE or .Dll File.
  • When you execute the .exe or .dll file, the code and all the other relevant information from the base class library is sent to the class Loader, who loads the code in memory.
  • Before code gets executed, The Just-in-Time (JIT) compiler translates the code from IL to native code (machine code). CLR supplies a JIT compiler for each supports CPU architecture. During the process of compilation, the JIT compiler compiles only the code that is required during execution instead of compiling the complete IL code.
  • During JIT Compilation, the code is also checked for type safety. Type Safety ensures that object are accessed in a compatible way. Type Safety also ensures that objects are isolated from each other and are therefore safe from any malicious corruption.
  • After Converted to native code, converted code is sent to .net runtime manager.
  • The .net runtime manager executed the code, while executed the code, a security check is performed to ensure that the code has the appropriate permission for accessing the available resources.

Features provided by CLR

Some of the features provided by the CLR are as follows:
  • Automatic memory management: - The CLR provides the Garbage Collection feature for managing the life time of object. This relives a programmer from memory management task.
  • Standard Type System: - The CLR Implement a formal Specification called the Common Type System (CTS). CTS is important part of rules that ensures that objects written in different language can interact with each other.
  • Language interoperability: - It is the ability of an application to interact with another application written in a different programming language. Language interoperability helps maximum code reuse. The CLR provides support for language interoperability by specifying and enforcing CTS and by providing metadata.
  • Platform Independence: - The Compiler compiles code language, which is CPU-independent. This means that the code can be executed from any platform that supports the .Net CLR.
  • Security Management: - In .net platform, Security is achieved through the code access Security (CAS) model. In
    the model, CLR enforces the restriction an managed code through the object called “permissions”. The CLR allows the code to perform only that task for which it has permissions. In other words, the CAS model specifies what the code can access instead of specifies who can access resources.
  • Type Safety: - This feature ensures that object is always accessed in compatible ways. Therefore the CLR will prohibit a code from assign a 10-byte value to an object that occupies 8 bytes.


    Benefits of CLR
Followings are some of benefits of the CLR
  • Performance improvement
  • The ability to easily use components developed in other languages.
  • Extensible types provided by library.
  • New Language features such as inheritance, interfaces etc.
  • Complete Object-Oriented design.
  • Very Strong Type Safety.
  • A good blend of Visual Basic simplicity and c++ power.
  • Syntax and keywords similar to c and c++.
  • Use of delegates rather than function pointers for increased type safety and security.

1 comment: