Tuesday, 19 April 2016

CLR (Common Language Runtime)

CLR is the heart of the .Net framework and it does 4 primary important things:

I. Garbage collection
II. CAS (Code Access Security)
III. CV (Code Verification)
IV. IL (Intermediate Language) to Native translation.

As part of Microsoft's .NET Framework, the Common Language Runtime (CLR) is a .NET thread, which runs on the background that manages the execution of programs written in any of several supported languages, allowing them to share common object-oriented classes written in any of the languages. The Common Language Runtime is somewhat comparable to the JVM (Java Virtual Machine) that is provide by Sun Microsystems for running programs compiled from the Javalanguage. Microsoft refers to its Common Language Runtime as a "Managed Execution Environment." A program compiled for the CLR does not need a language-specific execution environment and can easily be moved to and run on any System with Windows 2000 or Windows XP or later.

Programmes writing in any of Visual C++, Visual Basic, C#, F# or J# compile their programs into an intermediate form of code called Common Intermediate Language ( CIL ) in a portable execution ( PE ) file that can then be managed and executed by the Common Language Runtime. The programmer and the environment specify descriptive information about the program when it is compiled and the information is stored with the compiled program as metadata . Metadata, stored in the compiled program, tells the CLR what language was used, its version, and what class libraries will be needed by the program. The Common Language Runtime allows an instance of a class written in one language to call a method of a class written in another language. It also provides garbage collecting (returning unneeded memory to the computer), exception handling, and debugging services etc.

I. CAS (Code Access Security)
CAS is a security model in .NET that restricts what managed code can do based on its origin (e.g., from the internet, local machine, etc.).

It enforces permissions like file access, network access, etc.

Example: Code from a web download may be denied file system access.

Note: CAS is deprecated in .NET Core and .NET 5+. It was used in .NET Framework only.

II. CV (Code Verification)
Code Verification ensures managed code is type-safe and memory-safe before execution.

The CLR checks IL code for valid types, stack usage, and access boundaries.

Prevents unsafe operations like buffer overflows or pointer misuse.

Following snapshot explain's actual working of CLR in .NET environment.

Actual Woking of CLR in Dot Net Environment


(Practice Makes a Man Perfect)

No comments: