Unit - 1 VP-1
Unit - 1 VP-1
Unit – I
.NET Architecture
language (MSIL). The function of CLR is to convert managed code (MSIL) into machine native code
(executable code) and then execute the program. It means .Net application is compiled into byte code format
known as MSIL. During execution the CLR (JIT) compiler (Just-In-Time compiler) converts byte code into
processor native code and executes the application. CLR are also provides the following services / function:-
1) Memory management or garbage collection.
2) Loading and Execution of Program.
3) Convert intermediate language code to machine native code.
4) Exception Handling.
5) Class Loader.
6) Interoperability of other language.
7) Security.
Common Language Runtime has a following block diagram that show the working of CLR.
❖ Component of CLR –
There are following component of CLR –
1) Class Loader
2) Type Definition
3) COM marshaling
4) Debug manager
5) Exception manager
6) Code Manager
7) Security Engine
8) Thread Support
9) Garbage Collector
10) IL to Native Convertor (JIT)
11) BCL Support
that enables interoperability on the .Net platform Common Language Specification (CLS) is a set of basic
language features that .Net Languages needed to develop Applications and Services , which are compatible with
the .Net Framework. It supports reusability; therefore improve the efficiency of development process. CLS is
subset of CTS.
Here, some examples of CLS rules-
1) Use of new keyword to instantiate a class.
2) Array index should be ‘0’ based.
3) Multiple inheritances should not be support by language.
4) Third parity language should be object oriented.
CTS support two general categories of type, which are derived from base type called
“System.Object”:
1) Value types:-
Value types directly contain their data, and instances of value types are either allocated on the
stack or allocated inline in a structure.
2) Reference types:-
Reference types store a reference to the value's memory address, and are allocated on the heap.
Reference types can be self-describing types, pointer types, or interface types. The type of a reference
type can be determined from values of self-describing types. Self-describing types are further split into
arrays and class types. The class types are user-defined classes, boxed value types, and delegates.
➢ Managed Code -
The Managed code is whose execution is managed by CLR. Managed code is written in the high
level language like C#, VB.Net etc. Managed code always implemented by managed runtime environment.
The managed runtime environment provides different types of services like garbage collection, type checking,
exception handling, bounds checking, etc. to code automatically without the interference of the programmer.
The application is written in the languages like Java, C#, VB.Net, etc. are always aimed at runtime
environment services to manage the execution and the code written in these types of languages are known as
managed code. In the case of .NET Framework, the compiler always compiles the manages code in the
intermediate language(MSIL) and then create an executable code then the Just In Time Compiler of CLR
compiles the intermediate language in the native code which is understandable to machine. The managed code
also provides platform independence because when the managed code compiled into the intermediate language,
then the JIT compiler compiles this intermediate language in the architecture specific instruction.
➢ Intermediate Language –
Intermediate language (IL) is an object-oriented programming language designed to be used by compilers for
the .NET Framework before static or dynamic compilation to machine code. IL is a set of instructions that are
platform independent and are generated by the language-specific compiler from the source code. The IL is used
by the .NET Framework to generate machine-independent code as the output of compilation of the source code
written in any .NET programming language. IL is a stack-based assembly language that gets converted to byte
code during execution of a virtual machine. This term is also known as Microsoft intermediate language (MSIL)
or common intermediate language (CIL). MSIL includes instruction for loading, sorting, initializing and calling
methods or objects as well as instructions for arithmetic or logical operations, control flow, direct memory
access, exception handling or other operations.
➢ Garbage Collection –
C# and CLR work together to provide automatic memory management. We do not need to write
code to allocate or free the memory. The garbage collector (GC) manages the allocation and release of memory.
The garbage collector serves as an automatic memory manager. The CLR monitors memory usage and
automatically retrieves more when we need. It also frees memory automatically when it detect that it is no
longer being used. This is known as Garbage Collection. In an object oriented language including C# every time
object need to be allocated some memory space and require some resources like screen space, buffers and
hardware connection and so on. In many programming languages the release of previously allocated memory is
handled manually. E.g.- In C++, we use delete operator to free memory, that was allocated.
With Garbage Collector the user does not have to worry about tracking how much memory is in
use and when can it be free. Since, memory is finite; some sort of collection is required to free the memory.
Garbage collector manages the allocation and release of memory for automatically. This means automatic
memory management in .NET is done by Garbage Collector. Garbage Collector is the component of CLR.
When the garbage collector performs collection, it checks the objects in managed heap that are no longer being
used by the application and then reallocates that part of memory to some other objects.
Example -
****