English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Could someone explain me in detail whats the difference between managed and unmanaged code and what is the advantage of having managed code?
I am VB developer and learning .net, please elaborate in detail.
Thankyou

2007-01-04 01:12:54 · 4 answers · asked by Maxood 3 in Computers & Internet Programming & Design

4 answers

Managed Code vs Unmanaged code ..
Like the name says managed code is managed by something which is in this case .net framework. Essentially when you write something as unmanaged vb 6.0 or ansi c you directly communicate with Operating system . For example
when you want to allocate some memory space you demand it from OS. But in managed code you don't use OS you demand memory from .net framework and .net framework wants memory from os . If you allocated some memory from system you should Whyy?? Because in c,c++ memory management is very difficult and error prone operation by using managed code things get easier.

2007-01-04 01:57:45 · answer #1 · answered by A.D.T. 2 · 0 0

Fundamentally, the difference lies in two areas: the compiler and the runtime environment.

Compiler:

Managed Code: Compiler produces "Intermediate Language" (IL) code that cannot be directly executed by the CPU.

Unmanaged Code: Compiler produces "native machine code" that can be directly executed by the target CPU.

Run Time Environment:

Managed: The Intermediate Language code must be further compiled at run-time into native machine instructions by a "Just In Time" (JIT) compiler and then executed by the "Common Language Runtime (CLR)." (It's called "Common Language" because _all_ .NET-compatible compilers produce IL that conforms to the Common Language Specification.)

Unmanaged: The native machine code produced by the original language compiler is (essentially) run as is.

Advantages of Managed Code: (note: not exhaustive.)

1) Machine-independence (just like Java). _Theoretically_, all you need is a CLR for the target machine and operating system and the same program can run. In practice this possibility has yet to be _fully_ realized.

2) At run-time, the IL is verified runnable in terms of type safety and security.

3) Thwarts the age-old problem of "memory leaks." A memory leak occurs when a program asks the operating system (OS) to allocate memory (RAM) for it's use, and then never tells the OS it is done with it. The CLR manages the life time of objects and the memory they use and does "garbage collection."

4) CLR prevents unauthorized actions.

2007-01-04 02:15:00 · answer #2 · answered by Mike F 1 · 0 0

Unmanaged code is typical native code. It exists in bytecode format, optimized by the compiler.

Managed code exists in an intermediate format (Common Intermediate Language in .net) and is just-in-time compiled for the target platform. This language looks a lot like assembler, but is specifically compiled for the target machine each time it is run.

Managed code also keeps track of object allocation for you through a garbage collector, so you don't specifically allocate and delete memory. This eliminates a lot of pointer and memory problems that were common with C/C++.

2007-01-04 01:40:32 · answer #3 · answered by Pfo 7 · 0 0

If ur using Microsoft languages(like .internet C#) controlled code means one that passes by using MSIL(MicroSoft Intermediate Language) throughout compilation. some code want not be undergone MSIL, they r talked approximately as Unmanaged code. MSIL is needed in .internet because of the fact .internet is a platform that helps better than 25 programming languages like C,C++,VB,javascript,and so on... and so a Mediator is needed it fairly is easy for all languages to run or execute. wish this facilitates

2016-12-15 15:26:38 · answer #4 · answered by ? 4 · 0 0

fedest.com, questions and answers