• 0
Phoenix Programmer

إكسير إكسير مايكروسوفت دوت نت كود رقم 0002

سؤال

What is the difference between Managed Code and UnManaged Code in Microsoft Dot Net Programming Code?

Managed Code: 

          Is written to target the services of the managed runtime execution environment (like Common Language Runtime in .NET Framework). Themanaged code is always executed by a managed runtime execution environment rather than the operating system directly. Managed refers to a method of exchanging information between the program and the runtime environment. Because the execution of code is governed by the runtime environment, the environment can guarantee what the code is going to do and provide the necessary security checks before executing any piece of code. Because of the same reason the managed code also gets different services from the runtime environment like Garbage Collection, type checking, exception handling, and bounds checking … etc. This way managed code does not have to worry about memory allocations, and type safety … etc. Applications written in Java, C#, and VB.NET … etc. target a runtime environment which manages the execution and the code written using these types of languages. These languages are known as Managed Code. Managed code is always compiled into an Intermediate Language (MSIL in case of .NET Framework). The compiler used by .NET framework to compile managed codecompiles it into Intermediate Language and generates the necessarymetadata, which is symbolic information that describes all of the entry points and the constructs exposed in the Intermediate Language (e.g., methods, properties) and their characteristics. The Common Language Infrastructure(CLI) Standard describes how the information is to be encoded, and programming languages that target the runtime emit the correct encoding.

          In .NET Framework Managed Code runs within the .Net Framework’s CLR and benefits from the services provided by the CLR. When we compile the managed code, the code gets compiled to an intermediate language (MSIL) and an executable file is created. When a user runs the executable file, the Just In Time Compiler of CLR compiles the intermediate language into a native code specific to the underlying architecture. Since this translation happens by the managed execution environment (CLR), the managedexecution environment can make guarantees about what the code is going to do, because it can actually reason about it. It can insert traps and sort of protection around the code. If it’s running in a sandboxed environment, it can insert all the appropriate garbage collection hooks, exception handling, type safety, array bounce, index checking and so forth.

          Managed code also provides platform independence. As the managed code is first compiled to intermediate language, the CLR’s JIT Compiler takes care of compiling this intermediate language into the architecture specific instructions.

UnManaged Code: 

          Is directly executed by the Operating System. Typically, applications written in VB 6, C++, and C … etc. are all examples of unmanaged code.Unmanaged code typically targets the processor architecture and is always dependent on the computer architecture. UnManaged code is always compiled to target a specific architecture and will only run on the intended platform. This means that if you want to run the same code on different architecture, then you will have to recompile the code using that particular architecture. UnManaged code is always compiled to the native code which is architecture specific. When we compile unmanaged code, it gets compiled into a binary x86 image. This image always depends on the platform on which the code was compiled and cannot be executed on the other platforms that are different than the one on which the code was compiled. Unmanaged codedoes not get any services from the managed execution environment.

          In unmanaged code, the memory allocation, type safety, and security … etc. need to be taken care of by the developer. This makes unmanaged codeprone to memory leaks like buffer overruns and pointer overrides and so forth.

          UnManaged executable files are basically a binary image, x86 code, loaded into memory. The program counter gets put there and that’s the last the Operating System knows. There are protections in place around memory management and port I/O and so forth, but the system doesn’t actually know what the application is doing.

What Dot Net FrameWork programming languages can use UnMaaged Code?

          UnManaged code can be written with C++, and C# … etc. Dot Net FrameWork programming languages.

Why UnManaged Code is needed?

  • Legacy – native code long predates managed code, and there are still native apps to maintain.
  • Performance – all things being equal, native code should be faster and have a smaller memory footprint than managed code (things are rarely equal though, and for I/O bound tasks, the difference is negligible); also, non-deterministic garbage collection can play hell with real-time code.
  • System or hardware-specific hacks – native code may have access to system calls or libraries that the managed code may not (such as for parallel processing or vector processing, although I imagine most managed languages should be able to expose an API for such operations).
  • No Virtual Machine (Dot Net FrameWork RunTime Environment) available – you may be targeting a system for which no Virtual Machine has been developed, or doesn’t have the resources to run managed code (such as a microcontroller or other embedded system); also, your target system may not need the capabilities of a full-up Virtual Machine (predominately CPU-bound tasks, limited I/O … etc.).
  • Maximum speed of execution – The managed code layer adds around 10% overhead to the program.
  • Maximum flexibility – Some features of some APIs are unavailable through the managed code library. Using unmanaged APIs from a managed code program is possible but more difficult, and introduces its own performance issues.

Dot Net Code Elixir Number 0002:
https://goo.gl/gDi0kw

Draft 0002 Dot Net Code Elixir E-Book:
https://goo.gl/HrygWP

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

0 إجابة على هذا السؤال .

لاتوجد إجابات على هذا السؤال حتى الآن .

من فضلك سجل دخول لتتمكن من التعليق

ستتمكن من اضافه تعليقات بعد التسجيل



سجل دخولك الان

  • يستعرض القسم حالياً   0 members

    لا يوجد أعضاء مسجلين يشاهدون هذه الصفحة .