Before starting with CLR you need to understand .NET Framework first. So, actually what is the .NET Framework?
Well, it is a software framework in which we design and create wonderful applications (windows, web & mobile). This framework is introduced by Microsoft and backed by its community which means it has a great future with head support.
What Are The Components Of .NET Framework?
.NET Framework contains lots of components and CLR is the Key component for it and following is another component in Dot Net Framework, which we will discuss in other posts.
- .NET Framework Class Library.
- Common Language Runtime. – Will discuss in this blog
- Dynamic Language Runtimes (DLR)
- Application Domains.
- Runtime Host.
- Common Type System.
- Metadata and Self-Describing Components.
- Cross-Language Interoperability.
Introduction To CLR
The Common Language Runtime (CLR) is the main machine or key component of Microsoft Dot Net Framework and it manages the total execution of .NET programs. A process known as JIT ( just-in-time compilation) converts compiled code into machine language, which the computer’s CPU then executes.
Under .NET Framework, there are categories of the code into two types first manage code which runs and is executed under the CLR environment, and unmanaged code which not run and execute under the CLR environment.
What Is Managed Code?
Managed code is the resultant output of source code done by the compiler and that code is written in one of over 20 high-level programming languages that are used with the Microsoft .NET Framework. Examples of those languages are C#, J#, Microsoft Visual Basic Dot NET, Microsoft JScript, and Dot NET. On the other hand, unmanaged code refers to programs written in C, C++, and other languages that do not need a runtime to execute.
Features Of Common Language Runtime
CLR provides additional services including Base Class Library Support, thread management, memory management, type safety, exception handling, garbage collection, and security. All programs are written for the .NET framework, regardless of programming language, and are executed by the CLR. All versions of the .NET framework include CLR.
Base Class Library Support
It provides supports through class libraries to an application.
The execution of code parallel is called Threading and threads are runs under the Common Language Runtime. Threads are basically lightweight processes responsible for multitasking within a single application.
Helps in communication between the COM objects and application.
Common Language Specification (CLS)
Common Language Specification (CLS) under CLR is a set of rules by which languages must flow in order to make them compatible with other .NET languages.
CTS (Common Type System)
Data types of class members that are created in two different languages get compiled into the base common data type system.
The following can be regarded as the functions of the Common Type System. It:
- Makes it possible for the framework to be cross-language integration or platform independent, type safety, and high-performance code execution.
- Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.
- Provides primitive data types (such as Boolean, Byte, Char, Int32, and UInt64) used in application development.
This topic contains the following sections:
Types in DOT NET
Characteristics of Type Members
Types of DOT NET
All types in .NET are either value types or reference types.
Value types are data types whose objects are represented by the object’s actual value. If an instance of a value type is assigned to a variable, that variable is given a fresh copy of the value.
Reference types are data types whose objects are represented by a reference (similar to a pointer) to the object’s actual value. If a reference type is assigned to a variable, that variable references points to the original value. No copy is made.
The common type system in .NET supports the following five categories of types:
It enforces security permissions at code level security, folder-level security, and machine-level security using Dot Net Framework setting and tools provided by Dot Net.
Garbage Collector automatically releases memory of unused objects in an application and can be done by CLR automatically or forcefully by writing a code in an application about how memory management happens in CLR.
How JIT (JUST-IN-TIME) Works?
In short, our code gets compiled two times. On the first pass, it is compiled from higher language to MSIL (Microsoft Intermediate Language). During the second pass, the code (now an assembly in MSIL) is compiled into machine language which is understandable by the operating system.
This process is called Just-In-Time JIT compilation because it does not occur until the assembly is on the target machine. Due to this, the assembly is compiled in a very optimized and fastest possible machine language code. Also, it is also enhanced for your specific configuration.
Pre-JIT compiles complete source code into native code in a single compilation cycle. This is performed at the time of deployment of the application.
Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.
Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in a cache. When the same methods are called again, the compiled code from a cache is used for execution.
These methods are compiled the first time they are called, and then they are stored in a cache. When the same methods are called again, the compiled code from a cache is used for execution.
Any confusion or suggestions? Feel Free to add your valuable comments in the same regard!