UFO ET IT

"관리"코드 란 정확히 무엇입니까?

ufoet 2021. 1. 15. 07:41
반응형

"관리"코드 란 정확히 무엇입니까?


저는 거의 20 년 동안 C / C ++ 코드를 작성해 왔으며 Perl, Python, PHP 및 일부 Java도 알고 있으며 JavaScript를 직접 가르치고 있습니다. 하지만 .NET, VB 또는 C # 관련 작업을 한 적이 없습니다. 관리 코드는 정확히 무엇을 의미합니까?

Wikipedia 간단히 다음과 같이 설명합니다.

가상 머신의 관리하에 실행되는 코드

특히 Java가 (일반적으로) 관리 코드라고 명시되어 있으므로

  • 이 용어가 C # /. NET에만 적용되는 이유는 무엇입니까?
  • C #을 VM도 포함 된 .exe로 컴파일 할 수 있습니까? 아니면 패키지로 만들어 다른 .exe (a la java)에 제공해야합니까?

비슷한 맥락에서

  • .NET은 언어 또는 프레임 워크 이며 여기서 "프레임 워크"는 정확히 무엇을 의미합니까?

좋아요, 그것은 하나 이상의 질문입니다.하지만 제가 가진 한 업계에 종사해 온 사람에게는 지금 당장 N00B 같은 느낌이 듭니다 ...


C # 코드를 .exe로 컴파일하면 CIL (Common Intermediate Language) 바이트 코드로 컴파일됩니다. CIL 실행 파일을 실행할 때마다 Microsoft CLR (공용 언어 런타임) 가상 머신에서 실행됩니다. 따라서 .NET 실행 파일에 VM을 포함 할 수 없습니다. 프로그램이 실행될 모든 클라이언트 시스템에 .NET 런타임이 설치되어 있어야합니다.

두 번째 질문에 답하기 위해 .NET은 언어별로 다르지 않은 라이브러리, 컴파일러 및 VM 세트라는 점에서 프레임 워크입니다. 따라서 .NET 프레임 워크에서 C #, VB, C ++ 및 .NET 컴파일러가있는 다른 언어로 코딩 할 수 있습니다.

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

위 페이지에는 .NET 버전이있는 언어 목록과 해당 페이지에 대한 링크가 있습니다.


.Net이 무엇인지 혼동하는 데 혼자 있다고 생각하지 않습니다. 이미 다루어야 할 다른 답변이 있지만 다른 사람들을 위해이 정보를 버리겠습니다.

.Net "정말"이 무엇인지 확인하려면 c : \ Windows \ Microsoft.Net \ Framework로 이동하십시오.

거기에 설치 한 버전에 특정한 폴더가 표시됩니다. 예를 들어 v2.0.xxxxx 폴더로 이동하십시오.

그 폴더에는 프레임 워크가 있습니다. 기본적으로 .exe 파일과 .dll 파일이 표시됩니다. System. *. dll로 시작하는 모든 DLL 파일은 기본적으로 .Net 프레임 워크입니다.

해당 폴더에서 볼 수있는 .exe 파일은 개발자와 컴파일러를위한 유틸리티입니다. C #을 언급하셨습니다. csc.exe 파일을 찾습니다. 이것이 바로 C # 컴파일러입니다.

프로그램 구축은 정말 간단합니다. hello.cs 파일에 다음 코드를 넣으십시오.

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

그런 다음 명령 줄에서> csc hello.cs를 입력합니다.

그러면 .exe 파일이 생성됩니다. 그것을 실행하면 분명히 'hello world'가 뱉어집니다.

Console.WriteLine ()이라는 줄이 프레임 워크를 호출하고 있습니다. Console은 System 네임 스페이스 내에있는 개체이고 WriteLine ()은 정적 메서드입니다.

다음은 해당 Console.WriteLine () 메서드에 대한 디스 어셈블 된 코드입니다.

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

사람들이 "PHP 또는 .Net을 사용해야합니까?"또는 "Python 또는 .Net을 사용해야합니까"와 같은 말을 할 때 그것이 어떻게 잘못된 논의인지 알 수 있습니다. 그들은 분명히 언어를 프레임 워크와 비교하고 있습니다. C #은 언어이며 .Net 플랫폼에서 코드를 작성하는 데 사용할 수있는 많은 언어 중 하나 일뿐입니다. Console.WriteLine ()의 동일한 메서드는 C #, VB.Net, Pascal, C ++, Ruby, Python, F # 및 .Net 플랫폼에서 작동하도록 만들어진 다른 언어에서 호출 할 수 있습니다.

도움이 되었기를 바랍니다.

-키스


대부분의 경우 모든 메모리 할당이 "관리"된다는 사실을 나타냅니다. 관리 코드를 사용하는 경우 작업을 마쳤을 때 개체를 해제하는 것에 대해 걱정할 필요가 없습니다. 단순히 범위를 벗어나도록 허용하는 것은 VM이 결국 더 이상 참조가 없음을 인식하고 가비지가이를 수집하여 시스템에 메모리를 반환 함을 의미합니다.

반면에 관리되지 않는 코드는 참조를 삭제하기 전에 포인터를 명시 적으로 해제하지 않는 한 단순히 "누수"됩니다.


Microsoft가 .NET을 C / C ++ 및 기타 이전 언어와 구별하기 위해 선택한 용어이기 때문에 주로 .NET을 설명하는 데 사용됩니다. Microsoft는 C # /. NET과 Java 간의 유사점을 강조하고 싶지 않았기 때문에 일반적으로 Java와 관련된 용어가 아니기 때문에 선택했습니다 ( '가상 기계 코드'와 같은 이름으로 부르는 것과 반대). 훨씬 더 Java처럼 들립니다). 기본적으로 "관리 코드"의 사용은 기술 기반이 아닌 마케팅 기반 용어입니다.


특히 .NET 및 Visual C ++에서는 관리되지 않는 코드와 관리되는 코드를 모두 가질 수 있습니다. 이 용어는 메모리가 할당되고 '관리되는'방식을 나타냅니다.

관리되지 않는 코드는 익숙한 C ++ 항목입니다. 동적 메모리 할당 및 메모리의 명시 적 해제. .NET 런타임은 메모리를 관리하지 않으므로 '관리되지 않음'입니다.

반면에 관리되는 코드는 런타임에 의해 관리됩니다. 필요한 곳에 메모리를 할당하고 (메모리 공간이 아닌 변수를 선언하여) 런타임 가비지 수집기가 더 이상 필요하지 않은시기를 결정하고 모두 정리합니다. 가비지 수집기는 또한 효율성을 향상시키기 위해 메모리를 이동합니다. 런타임은 모든 것을 '관리'합니다.

위에서 언급했듯이 관리 및 관리되지 않는 코드를 작성할 수 있습니다.

관리되지 않음 :

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

관리 :

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

Notice the ref? That pretty much designates a Managed class. It gets very confusing when you mix the two kinds of code however. For instance, you want to save a reference pointer, (^) the managed equivalent of a pointer, to a Picture Box control within your unmanaged class. Since the garbage collector can move memory around, the next time you try to dereference the picture box it can not be found. The run-time does not tell your unmanaged code about it's memory changes.

Therefore you need to pin down the managed object in memory to allow your unmanaged code to keep track of it. Then there's unboxing and all kinds of other quirks that allow you to intermix the two. Code complexity is enormous!

Officially, managed/unmanaged might come down to the way code executes on the .NET stack. However, if you're coming from a c++ background, I hope this will be a little more relevant to you.


Managed means that the code is not compiled to native code, and thus runs under the auspices of a virtual machine. Java compiles to an intermediate format called bytecode, which the Java VM knows how to interpret and execute. All the .NET languages do a similar thing, compiling to IL (intermediate language) which the .NET runtime interprets. It's a little confusing because the .NET IL have .dll and .exe file endings.


The term managed is generally applied only to .NET because Microsoft uses the term. Microsoft generally doesn't use the term "virtual machine" in reference to a .NET managed execution environment.

.NET's "bytecode" (IL) is somewhat different from Java bytecode in that it was explicitly designed to be compiled into native code prior to execution in the managed environment, whereas Java was designed to be interpreted, but the concept of platform-independent code is similar.

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

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


At the risk of offending some, I suspect that the word managed was used so they could use the word unmanaged instead of compiled. While managed may mean more, the reality is it seems to be the used to distinguish mostly between what is pretty much just in time compiling (as the replacement for what was one once interpreted or pcode) and native compiled code.

Or put another way, which would you prefer to use:

a) Unmanaged code that may do uncontrollable things to the system.

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

Of course, they are actually the same thing.


In a similar vein, is .NET a language or a framework, and what exactly does "framework" mean here? <<

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

• A single universal interface for accessing Windows functionality:

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 executing .NET applications:

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

• The choice of 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.

.NET is a framework. The Common language Runtime (CLR) executes the Microsoft Intermediate Language (MSIL) code that is generated when a solution is compiled (i.e., it does not compile to machine code). You cannot contain the API within the exe, nor would you want to as it is quite large. The major benefit here is memory management (among some other security advantages and possibly others that I do not know about.)


I can answer the framework question. .NET is a framework, C#, VB.NET, etc are languages. Basically .NET provides a common platform of libraries to call (All the System.... dlls) that any language using .NET can call. All the .NET languages are compiled into MSIL (Microsoft Intermediate Language, better known as just IL) which can then be run on any PC with the appropriate .NET framework installed.


.NET is a framework. It can be used from many languages (VB.NET, C#, IronPython, boo, etc)

.NET always executes as interpreted, and no you cannot include the 'VM' inside the .exe. Any user wishing to run your .NET app must have the framework installed.


It can refer to any code executed by a virtual machine rather than directly by the CPU.

I think this enables things like garbage collection and array bounds checking.


Personally, I think the word "framework" is a bit of a misnomer.

.NET is a "platform", consisting of an execution environment (the CLR virtual machine) and a set of libraries. It's exactly analogous to Java or Perl or Python (none of which are ever referred to as "frameworks").

In most cases, the word "framework" is used for projects like Spring or Struts or QT, which sit on top of a platform (ie, providing no execution environment of their own) like a library.

But unlike a "library", a framework seeks to re-define the fundamental operations of the underlying platform. (Spring's dependency injection defies the constructor-calling logic of ordinary Java code. QT's signals-and-slots implementation defies ordinary C++ code.)

I know I'm just being a pedantic bastard, but to me, .NET is not a framework. It's a platform.


Managed Code--MSIL and IL and Managed Code are same.When we build our application the .dll or .exe files are generated in the Bin folder.These files are called as Managed code.Later these files are given to CLR to generate Native code which would be understood by OS.

ReferenceURL : https://stackoverflow.com/questions/57923/what-exactly-is-managed-code

반응형