This article is the Part 1 of the series of articles on the Interview Questions and Answers on .Net Framework, OOPS, ASP.Net, C#.Net, SQL Server, WCF Series.
CLR is Common Language Runtime is the runtime that converts a MSIL code into the host machine language code. It is the execution engine for .NET Framework applications. It provides a number of services, including:
- Code management (loading and execution)
- Memory Management
- Thread Management
- Conversion of IL to native code.
- Access to metadata (enhanced type information)
- Managing memory for managed objects (Garbage collection)
- Enforcement of code access security (Security Management)
- Exception handling, including cross-language exceptions
- Interoperation btw managed code, COM objects, and pre-existing DLL’s (unmanaged code and data)
- Support for developer services (profiling, debugging, and so on).
- Type safety.
Question 2 – What is CLR HOST?
A CLR host is an application that is responsible for loading the CLR into a process, creating application domains within the process, and executing user code within the application domains.
Examples of hosts that ship with the .NET Framework include:
- ASP.Net – An ISAPI filter that ships with ASP.NET loads the CLR and does the initialization necessary to handle web requests.
- Internet Explorer: – A MIME filter hooks into IE versions 5.01 and higher to execute managed controls referenced from HTML pages.
Question 3 – What is CTS?
CTS is Common Type System, which describes how types are declared, used and managed. CTS facilitate cross-language integration, type safety, and high performance code execution.
Example in VB you have “Integer” and in C++ you have “long” these data types are not compatible so the interfacing between them is very complicated. In order that these two different languages communicate Microsoft introduced Common Type System. So “Integer” data type in VB and “int” data type in C++ will convert it to System.int32, which is data type of CTS.
Question 4 – What is CLS?
CLS Is Common Language Specification, is a specification that defines the rules to support language integration. This is done in such a way, that programs written in any language (.NET compliant) can interoperate with one another. This also can take full advantage of inheritance, polymorphism, exceptions, and other features. It was always a dream of Microsoft to unite all different languages in to one umbrella and CLS is one-step towards that.
(IL) Intermediate Language Or (CIL) Common Intermediate Language Or (MSIL) Microsoft Intermediate Language, is one of the Core component of the .NET Framework. Any .NET source codes written in any .net supportive language (C#,VB.net etc), when compiled are converted to MSIL. This MSIL, when installed or at the Runtime, gets converted to machine code. The Runtime conversion of MSIL code to the machine code is handled by a component called as the Just In Time (JIT) Compiler.[ad]
It is a compiler which converts MS IL (Microsoft Intermediate Language) code to Native Code (i.e. CPU-specific code that runs on the same computer architecture). Just-In-Time compiler- it converts the language that you write in .Net into machine language that a computer can understand. There are 3 types of JITs
- Pre-JIT compiler (Compiles entire code into native code completely in a single Operation)
- Econo JIT compiler (Compiles only methods(Code) called at Runtime)
- Normal JIT compiler (Compiles only that part of code called at Runtime and places in cache)
The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. Windows PE is divided into 2 main sections.
- The first section includes the PE/COFF headers that references the contents within the PE file.
- The second section is the native image section which contains .data, .rdata, .rsrc, and .text sections.
Question 8 – What is Managed Code?
Managed code runs inside the environment of CLR i.e. .NET runtime. In short, all IL are managed code. However, if you are using some third party software example VB6 or VC++ component they are unmanaged code, as .NET runtime (CLR) does not have control over the source code execution of these languages.
A runtime-aware compiler compiles the IL into native executable code within a managed execution environment that ensures type safety, array bound and index checking, exception handling, and garbage collection. Also, many unproductive programming tasks are automatically taken care of, such as type safety checking, memory management, and destruction of unneeded objects. You can therefore focus on the business logic of your applications and write them using fewer lines of code. The result is shorter development time and more secure and stable applications.
As mentioned above the Unmanaged code will be one where
- The CLR cannot able to understand the code.
- The CLR cannot instruct the code.
- The second time compilation is unmanaged code. It is understood only by the machine not by the user.
Garbage collection is a process of releasing the memory used by the objects, which are no longer referenced. This is done in different ways and different manners in various platforms and languages.
When an program is loaded in the memory there will be a bunch of memory allocated for that particular program alone and loaded with memory. This bunch of memory is called Managed Heap(is nothing but a bunch of memory allocated for the program at run time). This amount of memory will only be used when an object is to be loaded in to the memory for that particular program.
This memory is separated in to three parts:
- Generation Zero – Smaller size
- Generation One – Medium size
- Generation Two – Larger size
When we try to create an object by using NEW keyword the system will,
- Calculate the number of bytes required for the object or type to be loaded in to the managed heap.
- The CLR then checks that the bytes required to allocate the object are available in the reserved region. IF the object fits, it is allocated at the address pointed to by NextObjPtr.
- These processes will happen at the Generation zero level.
Disclaimer – F5debug Interview Questions & Answers Series:
You may recopy extracts from these pages (“the material”) to individual third parties website or to the local system internal websites for their personal information, but only if:
You acknowledge the www.f5debug.net as the source of the material. Such acknowledgment should include reference to the www.f5debug.net in the copy of the material and should also include the words ” © Karthikeyan Anbarasan, www.f5debug.net “. You inform the third party that these conditions apply to him/her and that he/she must comply with them.