Managed Code vs Unmanaged Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Apologies if this has been discussed before. I have a hard time understanding
the difference between the two above. Can someone in simple layman terms
please explain why C/C++ is unmanaged while C# or anything in .Net is managed.

Believe me when i say that I have really searched the internet for answers
but 1) could not understand some of the definitions 2) doubted how authentic
the info was.
 
The simple answer is that .Net code gets run through the Just In Time
Compiler. The JIT "manages" all the execution of the code much like the
Java Virtual Machine does. It handles all the security and many other
issues that unmanaged code does not. C++ code gets compiled into machine
language code and nothing is handlling it's execution when you run the
program. That's how I understand the difference.

Chris
 
In addition, you can read up this article which, IMHO, explains in simple
terms what the terms managed/umanaged/native code mean:
http://www.developer.com/net/cplus/print.php/2197621

In .NET, the CLR - Common Language Runtime - 'manages' the execution of the
code produced by the various .NET compilers - which is MSIL (Microsoft
Intermediate Language) code and not native binary code (that can be directly
executed on a machine of a particular archtecture, for example, x86
architecture).

hope that helps..
Imran.
 
Opps, typed too fast. The JIT compiles it and the CLR manages the execution
of it.

Chris
 
I have read that security issues (preventing hacks from getting control)
was the driving issue.

A way to answer your question is that C++ deals directly with Windows or the
hardware. Whereas, the .Net languages communicate only with the Common
Language Runtime (CLR) which in turn communicates with Windows and the
hardware. In other words, the .Net languages are only allowed to do what the
CLR allows.

One of the differences between "Managed" and "Unmanaged" code is that
"Managed" code has its storage managed automatically. For example, the .Net
languages do not get or free storage; it is done automatically. C++ is
unmanaged and C++ applications still do their Malloc stuff, forget to free
storage when they should, cause "memory leaks", etc.

Bud Corazza
 
Back
Top