0% found this document useful (0 votes)
36 views14 pages

CLR CTS

Uploaded by

aaradhana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views14 pages

CLR CTS

Uploaded by

aaradhana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

.

NET Framework
Common Language Runtime and Common Type System
Common Language Runtime
• 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.

• CLR's intermediate language is called MSIL, i.e., Microsoft intermediate


language code.
• This code is platform-independent. It is comparable to byte code in java.
• Metadata is also generated during compilation and MSIL code and stored
in a file known as the Manifest file.
• A just-in-time compiler component of CLR converts MSIL code into native
code of the machine. This code is platform-dependent.
• CLR manages memory, threads, exceptions, code execution, code safety,
verification, and compilation.
CLR Execution Model
Managed / Unmanaged Code
• The code that runs with CLR is called managed code,
whereas the code outside the CLR is called unmanaged
code.
• The CLR also provides an Interoperability layer, which
allows both the managed and unmanaged codes to
interoperate.
Managed Code
• Any language that is written in the .NET framework is
managed code. Managed code use CLR, which looks
after your applications by managing memory, handling
security, allowing cross-language debugging, etc
Unmanaged Code
• The code developed outside the .NET framework is
known as unmanaged code. Applications that do not run
under the control of the CLR are said to be unmanaged.
This code is executed with the help of wrapper classes.
Managed Code vs Unmanaged Code
CLR Structure
Main Components of CLR
• Common Type System - CTS is a rich type system built into the CLR, it
implements various types (int, float, string, …) and operations on those
types.
• Common Language Specification - CLS is a set of specifications that all
languages and libraries need to follow and this will ensure
interoperability between languages.
• Garbage Collector - It helps manage memory by automatically
allocating memory according to the requirement. When objects are not
in use, it reclaims the memory allocated to them for future use.
• Just in Time Compiler - converts the MSIL code into native code (i.e.,
machine-specific code).
• Metadata - binary information about the program, either stored in a
CLR Portable Executable file (PE) along with MSIL code or in the
memory and
Assemblies - fundamental unit of physical code grouping which
consists of the assembly manifest, metadata, MSIL code, and a set of
resources like image files.
CLR Functions
• Converts the program into native code.
• Handles Exceptions
• Provides type-safety
• Memory management
• Provides security
• Improved performance
• Language independent
• Platform independent
• Garbage collection
• Provides language features such as inheritance, interfaces,
and overloading for object-oriented programs.
Common Type System
• CTS provides guidelines for declaring, using, and
managing data types at runtime.
• It offers cross-language communication.
• CTS provides the data types using managed code.
• A common type system helps in writing language-
independent code.
• It provides two categories of types,
• Value Type
• Reference Type
Value Type Reference Type
A value type stores the data. A Reference type stores a reference to the value.
Stack or inline structure is used. Heap memory is used for dynamic memory allocation.
This type holds the data directory. Reference Type does not hold actual data directly but
holds the address of data.
If one variable's value is copied to another, both the Whenever a reference type object is made, it copies
variables store data independently. the address and not actual data. Therefore two
variables will refer to the same data.
It can be of built-in types, user-defined, or Reference types can be self-describing types (string,
enumerations types. Array, Class types), pointer types, or interference
types.
MSIL – sample code
• It is low-level (machine) language, like Assembler, but is Object-
oriented.
.method private hidebysig static void Main()
cil managed
{
.entrypoint
// Code size 11 (0xb)
.maxstack 8
IL_0000: ldstr "Hello, world!"
IL_0005: call void
[mscorlib]System.Console::WriteLine(string)
IL_000a: ret
} // end of method HelloWorld::Main

You might also like