.Net Framework Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 3274 Page Views: 

Explain Managed and Unmanaged Code in .Net?



Posted By: Avi Date: 8 January 2010 01:57:09 PM
 Answer:

Managed code is code that has its execution managed by the .NET Framework Common Language Runtime. The .NET framework provides several core run-time services to the programs that run within it, for example exception handling, security, type checking, garbage collection, etc. Example of managed code includes all the programs written in C#, VB.Net, and other .Net supported langauges.

Unmanaged code does not execute under the control of .Net Framework while it executes directaly under the control of operating system. Typically applications written in VB 6.0, C++, C, Win32, COM, etc are all examples of unmanaged code. In unmanaged code the memory allocation, type safety, security, etc needs to be taken care of by the developer.


Posted By: eTechPlanet


Date: 8 January 2010 01:57:09 PM

Managed Code is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer. The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code you've created. This assembly is the one-stop-shopping unit of deployment in the .NET world. You copy it to another server to deploy the assembly there—and often that copying is the only step required in the deployment.

Unmanaged code is what you use to make before Visual Studio .NET 2002 was released. Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler you may still have kicking around on your hard drive all produced unmanaged code. It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same. It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system. And importantly, it got them from the operating system explicitly, by asking for them, usually by calling an API provided in the Windows SDK. More recent unmanaged applications got operating system services through COM calls.


Posted By: Johndecruse


Date: 30 January 2010 04:27:49 AM

The code, which is developed in .NET framework, is known as managed code. This code is directly executed by CLR with help of managed code execution. Any language that is written in .NET Framework is managed code. Managed code uses CLR which in turns looks after your applications by managing memory, handling security, allowing cross - language debugging, and so on.

Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with code of VB, ASP and COM are examples of unmanaged code. Unmanaged code can be unmanaged source code and unmanaged compile code. Unmanaged code is executed with help of wrapper classes.


Posted By: Daniel


Date: 16 February 2010 02:48:03 AM

What Is Managed Code?

Managed Code is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer. The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code you've created. This assembly is the one-stop-shopping unit of deployment in the .NET world. You copy it to another server to deploy the assembly there—and often that copying is the only step required in the deployment.
Managed code runs in the Common Language Runtime. The runtime offers a wide variety of services to your running code. In the usual course of events, it first loads and verifies the assembly to make sure the IL is okay. Then, just in time, as methods are called, the runtime arranges for them to be compiled to machine code suitable for the machine the assembly is running on, and caches this machine code to be used the next time the method is called. (This is called Just In Time, or JIT compiling, or often just Jitting.)
As the assembly runs, the runtime continues to provide services such as security, memory management, threading, and the like. The application is managed by the runtime.
Visual Basic .NET and C# can produce only managed code. If you're working with those applications, you are making managed code. Visual C++ .NET can produce managed code if you like: When you create a project, select one of the application types whose name starts with .Managed., such as .Managed C++ application.

What Is Unmanaged Code?

Unmanaged code is what you use to make before Visual Studio .NET 2002 was released. Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler you may still have kicking around on your hard drive all produced unmanaged code. It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same. It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system. And importantly, it got them from the operating system explicitly, by asking for them, usually by calling an API provided in the Windows SDK. More recent unmanaged applications got operating system services through COM calls.
Unlike the other Microsoft languages in Visual Studio, Visual C++ can create unmanaged applications. When you create a project and select an application type whose name starts with MFC, ATL, or Win32, you're creating an unmanaged application.
This can lead to some confusion: When you create a .Managed C++ application., the build product is an assembly of IL with an .exe extension. When you create an MFC application, the build product is a Windows executable file of native code, also with an .exe extension. The internal layout of the two files is utterly different. You can use the Intermediate Language Disassembler, ildasm, to look inside an assembly and see the metadata and IL. Try pointing ildasm at an unmanaged exe and you'll be told it has no valid CLR (Common Language Runtime) header and can't be disassembled—Same extension, completely different files.


Posted By: resumedocket


Date: 26 April 2010 04:37:41 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image k8jSeW
Related Questions
.Net Framework : What's new in .Net Framework 3.0?

What's new in .Net Framework 3.0?

There are no major architectural changes in .Net Framework 3.0. The version of Common Language Runti....
Category: .Net Framework Date: 12/4/2009 11:32:57 PM
.Net Framework : Explain CLR (Common Language Runtime) and its functionalities?

Explain CLR (Common Language Runtime) and its functionalities?

Common Language Runtime (CLR) is the engine available in .Net Framework to compile and run the progr....
Category: .Net Framework Date: 11/30/2009 3:42:09 PM
.Net Framework : How Just in Time Compiler Works?

How Just in Time Compiler Works?

.Net Framework uses two step compilation process. We write code in C#, VB.Net, or in other supportin....
Category: .Net Framework Date: 11/30/2009 2:53:38 PM
.Net Framework : Describe the difference between a Thread and a Process?

Describe the difference between a Thread and a Process?

A process is a unit of execution which has its own data regarding the source, has its own memory spa....
Category: .Net Framework Date: 10/30/2009 7:29:42 AM
.Net Framework : What namespaces and classes are typically used to develop Windows Services in .Net?

What namespaces and classes are typically used to develop Windows Services in .Net?

Namespace: 1) System.ServiceProcess Classes: 1) ServiceBase 2) ServiceProcessInstaller 3) ServiceIn....
Category: .Net Framework Date: 9/30/2009 7:18:12 AM