Skip to main content
3 answers
3
Asked 522 views

what is the different between Native programming VS managed programming?

#career

+25 Karma if successful
From: You
To: Friend
Subject: Career question for you

3

3 answers


1
Updated
Share a link to this answer
Share a link to this answer

S.’s Answer

Hi Maihan, programs written in a native language (C, C++) are compiled into "machine code" that runs directly on the CPU of the host machine. This offers high performance and usually allows you to use all special features of the host CPU such as enhanced math instructions.

Programs written in "managed" languages like Java and C# compile the code into an intermediate form called bytecode and provide a virtual machine that can run the bytecode efficiently on the CPU of the host machine. An advantage of bytecode is that it can be run on multiple types of CPUs (ie. ARM, x86), as long as you have a virtual machine for that CPU type. Managed languages also typically "manage" the memory usage of your objects/variables so that you do not have to reserve and release memory for each piece of data that you want to store.

Managed languages are more modern and typically more programmer-friendly but because they use bytecode that runs in a virtual machine and manage memory automatically, they can be slower when executing than native programs. However, for many types of programs, it is more effective to write in a managed language because of greater programmer productivity (even if the performance is a little lower).
1
1
Updated
Share a link to this answer
Share a link to this answer

David’s Answer

Native code is written in native machine language of the computer it is running on and is executed by the computer's processor. Managed code is written in a special language that requires another program to run it.
1
0
Updated
Share a link to this answer
Share a link to this answer

Brinda’s Answer

Native code and managed code looks identical if you only look at the source code, but they are applied and executed in completely different ways.
Native code is written in the "native" machine language of the computer that it is running on and is executed directly by the processor. Managed code is written in a special language that requires another program to run.
Managed Code is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer. The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes of the code you've created. This assembly is the core unit of deployment in .NET. You copy it to another server to deploy the assembly there.
Managed code runs in the Common Language Runtime. The runtime offers a wide variety of services to your running code. In the usual course of events, it first loads and verifies the assembly to make sure the IL is okay. Then the runtime arranges for them to be compiled to machine code suitable for the machine the assembly is running on, and caches this machine code to be used the next time the method is called. This is called Just In Time, or JIT compiling.

The phrase native code is used in two situations. Many people use it as a synonym for unmanaged code. That is the code built with an older tool, or purposely chosen in Visual C++, that does not run in the runtime, but instead runs natively on the machine. This can be a complete application, or it might be a COM component or DLL that is being called from managed code using COM Interop or PInvoke. These are the two powerful tools that let you use your old code when you move to the new world. it emphasizes that the code does not get the services of the runtime.
For example, Code Access Security in managed code helps you to prevent code loaded from another server and put a restriction from performing certain destructive actions. On the other hand, if your application calls out to unmanaged code loaded from another server, you won't get that protection.

0