NEWS

Tuesday, March 23, 2010

Managed vs. unmanaged code


  • Managed code runs through a runtime which is a software layer that the
    application communicates due to which many functions are automatically done. Some of these functions are garbage collecting and exception handling.

  • A programmer needs to write many common functions in an unmanaged code. So functions like garbage collecting, exception handling, etc have to be handled
    explicitly.

Explain - consuming unmanaged DLL functions using PInvoke.


PInvoke = Platform invoke.

Calling a function located in an unmanaged DLL library from .NET framework is called consuming unmanaged DLL function.

When PInvoke calls an unmanaged function,

The DLL containing the function is located and loaded it into memory.

Then the function arguments are pushed into the stake and then the data is marshalled required.


And then the control is transferred to the unmanaged function.


PInvoke throws exceptions generated by the unmanaged function to the managed caller.


Explain how managed code slower than unmanaged code.


Managed code executes under the management of a virtual machine. It is executed by a common language runtime environment rather than directly by the operating system. Tasks such as Exception handling and GC too are handled in the managed code environment. Due to all these reasons, managed code is slower than the unmanaged code.

No comments:

Post a Comment