0% found this document useful (0 votes)
0 views

NET Common Language Runtime

.NET Common Language Runtime (CLR) is a runtime environment that executes code written in various .NET languages, converting it from Microsoft Intermediate Language (MSIL) to machine code. Key components of CLR include the Common Type System (CTS), Common Language Specification (CLS), Garbage Collector, and Just-In-Time (JIT) compiler, which together facilitate memory management, language interoperability, and security. CLR also provides support for base class libraries, exception handling, and debugging, making it a crucial part of the .NET framework architecture.

Uploaded by

karanranvir061
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

NET Common Language Runtime

.NET Common Language Runtime (CLR) is a runtime environment that executes code written in various .NET languages, converting it from Microsoft Intermediate Language (MSIL) to machine code. Key components of CLR include the Common Type System (CTS), Common Language Specification (CLS), Garbage Collector, and Just-In-Time (JIT) compiler, which together facilitate memory management, language interoperability, and security. CLR also provides support for base class libraries, exception handling, and debugging, making it a crucial part of the .NET framework architecture.

Uploaded by

karanranvir061
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

.

NET Common Language Runtime (CLR)


.NET CLR is a runtime environment that manages and executes the code written in
any .NET programming language. CLR is the virtual machine component of the .NET
framework.

The execution of a .NET Application

Suppose you have written a C# program and save it in a file which is known as the
Source Code.

 Language specific compiler compiles the source code into the MSIL (Microsoft
Intermediate Language) which is also known as the CIL(Common
Intermediate Language) or IL(Intermediate Language) along with its
metadata. Metadata includes all the types, actual implementation of each
function of the program. MSIL is machine-independent code.
 Now CLR comes into existence. CLR provides the services and runtime
environment to the MSIL code. Internally CLR includes the JIT(Just-In-Time)
compiler which converts the MSIL code to machine code which further
executed by CPU. CLR also uses the .NET Framework class libraries.
Metadata provides information about the programming language,
environment, version, and class libraries to the CLR by which CLR handles
the MSIL code. As CLR is common so it allows an instance of a class that
written in a different language to call a method of the class which written in
another language.

As the word specify, Common means CLR provides a common runtime or execution
environment as there are more than 60 .NET programming languages.
The Main components of CLR:
o Common type system
o Common language speciation
o Garbage Collector
o Just in Time Compiler
o Metadata and Assemblies

Common Language Specification (CLS):

It is responsible for converting the different .NET programming language


syntactical rules and regulations into CLR understandable format. Basically, it
provides Language Interoperability. Language Interoperability means providing
execution support to other programming languages also in .NET framework.

Language Interoperability can be achieved in two ways :

1. Managed Code: The MSIL code which is managed by the CLR is known as the
Managed Code. For managed code CLR provides three .NET facilities:
2. Unmanaged Code: Before .NET development, programming languages
like.COM Components & Win32 API do not generate the MSIL code. So these
are not managed by CLR rather managed by Operating System.

Common Type System (CTS):

Every programming language has its own data type system, so CTS is responsible
for understanding all the data type systems of .NET programming languages and
converting them into CLR understandable format which will be a common format.

There are 2 Types of CTS that every .NET programming language have :

1. Value Types: Value Types will store the value directly into the memory
location. These types work with stack mechanisms only. CLR allows memory
for these at Compile Time.
2. Reference Types: Reference Types will contain a memory address of value
because the reference types won’t store the variable value directly in
memory. These types work with Heap mechanism. CLR allot memory for
these at Runtime.

Garbage Collector:

Garbage Collector is a component of CLR that works as an automatic memory


manager. It helps manage memory by automatically allocating memory according
to the requirement. It allocates heap memory to objects. When objects are not in
use, it reclaims the memory allocated to them for future use. It also ensures the
safety of objects by not allowing one object to use the content of another object.

JIT(Just In Time Compiler):

It is responsible for converting the CIL(Common Intermediate Language) into


machine code or native code using the Common Language Runtime environment.

Metadata:

A Metadata is a binary information about the program, either stored in a CLR


Portable Executable file (PE) along with MSIL code or in the memory. During the
execution of MSIL, metadata is also loaded into memory for proper interpretation
of classes and related. Information used in code. So, metadata helps implement
code in a language-neutral manner or achieve language interoperability.

Assemblies:

An assembly is a fundamental unit of physical code grouping. It consists of the


assembly manifest, metadata, MSIL code, and a set of resources like image files. It
is also considered a basic deployment unit, version control, reuse, security
permissions, etc.

.NET CLR Functions


Following are the functions of the CLR.

o It converts the program into native code.


o Handles Exceptions
o Provides type-safety
o Memory management
o Provides security
o Improved performance
o Language independent
o Platform independent
o Garbage collection
o Provides language features such as inheritance, interfaces, and overloading for
object-oriented programs.

Architecture of Common Language Runtime


A diagram that demonstrates the architecture of Common Language Runtime is given as
follows:
Following is the component structure of Common Language Runtime.

There are multiple components in the architecture of Common Language Runtime.


Details about these are given as follows:

 Base Class Library Support: The Common Language Runtime provides support for
the base class library. The BCL contains multiple libraries that provide various
features such as Collections, I/O, XML, DataType definitions, etc. for the
multiple .NET programming languages.
 Thread Support: The CLR provides thread support for managing the parallel
execution of multiple threads. The System.Threading class is used as the base
class for this.
 COM Marshaller: Communication with the COM (Component Object Model)
component in the .NET application is provided using the COM marshaller. This
provides the COM interoperability support.
 Type Checker: Type safety is provided by the type checker by using the Common
Type System (CTS) and the Common Language Specification (CLS) that are
provided in the CLR to verify the types that are used in an application.
 Exception Manager: The exception manager in the CLR handles the exceptions
regardless of the .NET Language that created them. For a particular application,
the catch block of the exceptions are executed in case they occur and if there is no
catch block then the application is terminated.
 Security Engine: The security engine in the CLR handles the security permissions
at various levels such as the code level, folder level, and machine level. This is
done using the various tools that are provided in the .NET framework.
 Debug Engine: An application can be debugged during the run-time using the
debug engine. There are various ICorDebug interfaces that are used to track the
managed code of the application that is being debugged.
 JIT Compiler: The JIT compiler in the CLR converts the Microsoft Intermediate
Language (MSIL) into the machine code that is specific to the computer
environment that the JIT compiler runs on. The compiled MSIL is stored so that it is
available for subsequent calls if required.
 Code Manager: The code manager in CLR manages the code developed in the .NET
framework i.e. the managed code. The managed code is converted to intermediate
language by a language-specific compiler and then the intermediate language is
converted into the machine code by the Just-In-Time (JIT) compiler.
 Garbage Collector: Automatic memory management is made possible using the
garbage collector in CLR. The garbage collector automatically releases the memory
space after it is no longer required so that it can be reallocated.
 CLR Loader: Various modules, resources, assemblies, etc. are loaded by the CLR
loader. Also, this loader loads the modules on demand if they are actually required
so that the program initialization time is faster and the resources consumed are
lesser.

You might also like