What is managed code?

I have been writing C / C ++ code for almost twenty years, and I know Perl, Python, PHP and some Java, and I also learn JavaScript myself. But I never did any .NET, VB or C #. What does managed code mean?

Wikipedia describes it simply as

Code that runs under a virtual machine

and it says that Java is (usually) managed code, so

  • why does this term seem to apply only to C # /. NET?
  • Can you compile C # to .exe, which also contains a virtual machine, or do you need to pack it and transfer it to another .exe (a la java)?

In a similar vein

  • Is it a .NET language or framework, and what exactly does a framework mean here?

OK, so there is more than one question, but for those who have been in the industry as long as I have, I feel more like the N00B-ish right now ...

+50
c # managed-code
Sep 11 '08 at 23:38
source share
15 answers

When you compile C # code in .exe, it is compiled by the Common Intermediate Language (CIL) bytecode. Whenever you run the CIL executable, it runs on the Microsoft Common Language Runtime (CLR) virtual machine. Thus, it is not possible to include the virtual machine in the .NET executable. You must have the .NET runtime installed on any client computers that your program will run on.

To answer your second question, .NET is the foundation, as it is a collection of libraries, compilers, and virtual machines that are not linguistic. This way you can encode the .NET Framework in C #, VB, C ++ and any other languages ​​that have the .NET compiler.

https://bitbucket.org/brianritchie/wiki/wiki/.NET%20Languages

The page above contains a list of languages ​​in which there are versions of .NET, as well as links to their pages.

+34
Sep 11 '08 at 23:47
source share

I don’t think that you are alone in confusing me. There are already other answers that you should have covered, but I will throw this information out for others.

To find out that .Net is “valid,” simply go to c: \ Windows \ Microsoft.Net \ Framework

There you will see folders that match your version (s). Go to the v2.0.xxxxx folder if you installed it, for example.

This folder contains the framework. Basically you will see a bunch of .exe files and DLL files. All DLL files that start with System. *. Dlls are essentially the .Net framework.

The .exe files that you see in this folder are utilities for developers as well as compilers. You mentioned C #. Locate the csc.exe file. This is your C # compiler.

Building a program is very simple. Add the following code to the hello.cs file.

using System; class Program { static void Main(string[] args) { Console.WriteLine("hello world"); } } 

Then at the command prompt, type type> csc hello.cs

This will create a .exe file for you. Run it and it will obviously spit out “hello world”.

A line that says Console.WriteLine () calls in the Framework. The console is an object that lives in the System namespace, and WriteLine () is a static method.

This is the disassembled code for this Console.WriteLine () method:

 [HostProtection(SecurityAction.LinkDemand, UI=true)] public static void WriteLine(string value) { Out.WriteLine(value); } 

When people say things like “Should I use PHP or .Net?”, Or “Should I use Python or .Net”, you start to see how to say it wrong. They obviously compare the language with the Framework. C # is a language, and it is just one of many languages ​​that you can use to write code on top of the .Net platform. The same Console.WriteLine () method can be called from C #, VB.Net, Pascal, C ++, Ruby, Python, F # and any other language that was created to work on top of the .NET platform.

I hope this helps.

-Keith

+10
Sep 20 '08 at 13:45
source share

It is mainly used to describe .NET, because Microsoft has decided to differentiate .NET from C / C ++ and other older languages. Microsoft chose this because it was not a term that was usually associated with Java, because they did not want to emphasize the similarities between C # /. NET and Java (unlike calling it as “virtual machine code”, the sound is much more like Java). In principle, the use of “managed code” is driven by marketing, and not from a technical point of view, terminology.

+9
Sep 11 '08 at 23:44
source share

This basically refers to the fact that all your memory allocations are “managed” for you. If you use managed code, you don’t have to worry about freeing your objects when you are done with them. Just letting them go out of scope will mean that the virtual machine will eventually recognize that there are no more references to them, and whether garbage will collect them, returning memory to the system.

Unmanaged code, on the other hand, simply “leaks out” unless you explicitly release your pointers before dropping the links.

+9
Sep 11 '08 at 23:46
source share

In .NET and Visual C ++, you can have both unmanaged and managed code. The terms refer to how memory is allocated and "managed."

Unmanaged code will be the C ++ stuff you're used to. Dynamic memory allocation and explicit memory release. The .NET runtime does not manage memory for you, so it is "unmanaged."

Managed code, on the other hand, is managed by IS at runtime. You allocate memory where necessary (by declaring variables, not memory space), and the runtime garbage collector determines when it is no longer needed and clears everything. The garbage collector will also move memory to improve efficiency. Runtime "controls" everything for you.

As I mentioned above, you can write code that is managed and unmanaged.

uncontrollable:

 class Bar : public Foo { private: int fubar; public: Bar(int i) : fubar(i) {} int * getFubar() { return * fubar; } } 

Managed:

 public ref class Bar : public Foo private: int fubar; public: Bar(int i) : fubar(i) {} int ^ getFubar() { return ^ fubar; } } 

Pay attention to ref? This pretty much means a managed class. This gets very confusing when you mix two types of code. For example, you want to keep a reference pointer (^) the managed equivalent of a pointer to a Picture Box control in an unmanaged class. Since the garbage collector can move memory around, the next time you try to dereference an image window, it cannot be found. Runtime does not inform your unmanaged code of memory changes.

Therefore, you need to bind a managed object in memory so that your unmanaged code tracks it. Then there is unboxing and all kinds of other quirks that allow you to mix the two. The complexity of the code is huge!

Formally managed / unmanaged can come down to how code runs on the .NET stack. However, if you come from a C ++ background, I hope this will be a little more relevant for you.

+6
Sep 20 '08 at 13:22
source share

The term managed usually only applies to .NET because Microsoft uses the term. Microsoft generally does not use the term "virtual machine" in relation to the runtime driven by .NET.

.NET "bytecode" (IL) differs somewhat from Java bytecode in that it was explicitly designed to compile into native code before being executed in a controlled environment, while Java was intended to be interpreted, but the concept of platform-independent code is similar.

The ".NET Framework" is basically a huge collection of libraries provided by Microsoft, containing thousands of classes that can be used to develop applications.

Compiled C # .exe contains platform-independent code that can be run in any .NET compatible environment, including Mono. However, the runtime is usually distributed separately from the applications that use it.

+3
Sep 11 '08 at 23:43
source share

Managed means that the code is not compiled into native code and thus runs under the auspices of a virtual machine. Java is compiled into an intermediate format called bytecode, which the Java VM knows how to interpret and execute. All .NET languages ​​perform a similar task by compiling IL (an intermediate language) that the .NET runtime interprets. This is a bit confusing because .NET IL has the endings of .dll and .exe.

+3
Sep 11 '08 at 23:45
source share

At the risk of offending some, I suspect that the word used was used so that they could use the word uncontrollable, rather than compiled. While control can mean more, the reality is that it is used to distinguish mainly between what is largely performed at compile time (as a replacement for what was once interpreted or pcode) and native compiled code .

Or enter another method that you prefer to use:

a) Unmanaged code that can do uncontrolled things in the system.

b) Native compiled code that is fast, reliable and close to the OS.

Of course, they are actually the same thing.

+2
Sep 12 '08 at 4:20
source share

In the same vein, .NET is a language or framework, and what does “wireframe” mean here? & L; <

.NET is Microsoft's modern enterprise software platform. It consists of:

• One universal interface for accessing Windows features:

 o The .NET Framework Class Library (FCL). o The FCL provides a rich set of high-level functionality for developers. 

• A single universal language and runtime for .NET applications:

 o Common Language Runtime (CLR) executes Common Intermediate Language (CIL). o The CLR is God: it runs, controls, and polices everything. 

• Select multiple languages ​​for developing .NET applications:

 o Every development language is compiled to CIL, which is run by the CLR. o C# and VB are the two main development languages. 
+2
Sep 20 '08 at 13:43
source share

.NET is the foundation. Common Language Runtime (CLR) executes Microsoft Intermediate Language Code (MSIL), which is generated when the solution is compiled (i.e., it does not compile for machine code). You cannot contain the API in exe and do not want to, since it is quite large. The main advantage here is memory management (among some other security benefits, and possibly others that I don't know about).

+1
Sep 11 '08 at 23:44
source share

I can answer the question about the structure ..NET is the environment, C #, VB.NET, etc. - these are languages. Basically, .NET provides a common platform for calling libraries (All the System .... dll), which any language can call using .NET. All .NET languages ​​are compiled into MSIL (Microsoft Intermediate Language, better known as IL), which can then be run on any PC with the .NET platform installed.

+1
Sep 11 '08 at 23:45
source share

.NET is the foundation. It can be used in many languages ​​(VB.NET, C #, IronPython, boo, etc.)

.NET is always executed as interpreted, and you cannot include "VM" inside .exe. Any user who wants to run your .NET application must have an installed infrastructure.

0
Sep 11 '08 at 23:42
source share

It can refer to any code executed by the virtual machine, and not directly to the CPU.

I think this allows things like garbage collection and checking the boundaries of an array.

0
Sep 11 '08 at 23:48
source share

Personally, I think the word wireframe is a little wrong.

.NET is a "platform" consisting of a runtime (CLR virtual machine) and a set of libraries. This is exactly the same as Java or Perl or Python (none of which are ever referred to as "frameworks").

In most cases, the word wireframe is used for projects such as Spring or Struts or QT, which are located on top of the platform (that is, do not create a runtime), such as a library.

But unlike the “library,” the structure seeks to redefine the basic operations of the underlying platform. (Spring dependency injection ignores the constructor logic of regular Java code. Implementing QT signals and slots challenges the regular C ++ code.)

I know that I'm just a pedantic bastard, but for me .NET is not the foundation. This is a platform.

0
Oct 08 '08 at 19:04
source share

Managed Code - MSIL and IL and managed code are the same. When we create our application, .dll or .exe files are created in the Bin folder. These files are called as managed code. Complete these files for the CLR to generate your own code that the OS will understand.

-one
May 21 '16 at 3:31
source share



All Articles