What is the difference between Managed Code and Unmanaged Code?
Unmanaged
code is the code that is directly executed by the Operating System.
The unmanaged code is architecture specific it can be run only in the
machine where it has been complied, the complier transforms the code
into the machine language which is then executed, in case it needs to
be run in a different machine it needs to be complied again. In
unmanaged code the developer needs to take care of the security,
memory management etc. Few e.g. are VB 6.0, C++, C etc.
On
the other hand the Managed Code is the code that is not targeted
directly to the Operating System rather to the Managed Runtime
Execution Environment. For the .NET Framework it is known as CLR
(Common Language Runtime). When a managed code is complied it is
transformed into MSIL (Microsoft Intermediate Language, currently
known as CIL (Common Intermediate Language)) and an executable is
created and also the meta data is created which describes the
characteristics of the methods and properties. The CLI specifies the rules as to how this meta data
is exposed. When
the executable is run by the user the CLR’s JIT (Just In Time Compiler) complies the MSIL into the native code specific to the
underlying architecture.
Since
the managed code is complied into an intermediate language it is
machine independent and takes the services of the managed environment
for e.g. security checks, garbage collection, exception handling etc.
More .Net...Interview Questions and answers
ReplyDeleteLing