[C#] Marshal.Copy()란 무엇인가?

프로그래밍/그 외2018. 4. 12. 14:47

안녕하세요. 개발자 드리머즈입니다.


Marshal.Copy()에 대해 조사해봤습니다.


https://msdn.microsoft.com/ko-kr/library/ms146631(v=vs.110).aspx에 설명이 있습니다.


Copies data from an unmanaged memory pointer to a managed 8-bit unsigned integer array.

관리되지 않는?(unmanaged) 메모리를 가리키는 포인터의 데이터를 관리가 되는?(managaed) 8비트 unsigned integer 배열로 복사하는 함수라고 합니다.


unmanaged 메모리, managed 메모리가 무엇인지 찾아봤습니다.

https://stackoverflow.com/questions/1345377/unmanaged-memory-and-managed-memory?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa에 설명이 있습니다.


It is all the same physical memory. The difference is who is controlling it.

The Microsoft definition is that managed memory is cleaned up by a Garbage Collector (GC), i.e. some process that periodically determines what part of the physical memory is in use and what is not.

Unmanaged memory is cleaned up by something else e.g. your program or the operating system. 


둘다 같은 메모리인데 누가 그 메모리를 쓰느냐에 따라 달라진다고 합니다. managed 메모리는 가비지 컬랙터(GC, Garbage Collectr)에 의해 정리가 되는 메모리입니다. 이와 달리 unmanaged 메모리는 프로그램 코드나 운영체제에 의해 정리가 되는 메모리입니다.


아래의 내용도 좋은 것 같습니다.

https://stackoverflow.com/questions/3563870/difference-between-managed-and-unmanaged


Managed Code

Managed code is what Visual Basic .NET and C# compilers create. It runs on the CLR (Common Language Runtime), which, among other things, offers services like garbage collection, run-time type checking, and reference checking. So, think of it as, "My code is managed by the CLR."

Visual Basic and C# can only produce managed code, so, if you're writing an application in one of those languages you are writing an application managed by the CLR. If you are writing an application in Visual C++ .NET you can produce managed code if you like, but it's optional.


Unmanaged Code

Unmanaged code compiles straight to machine code. So, by that definition all code compiled by traditional C/C++ compilers is 'unmanaged code'. Also, since it compiles to machine code and not an intermediate language it is non-portable.

No free memory management or anything else the CLR provides.

Since you cannot create unmanaged code with Visual Basic or C#, in Visual Studio all unmanaged code is written in C/C++.


간단하게 말해 C#으로 작성되는 코드는 Managed Code이며, 전통적인 C/C++ 컴파일러에 의해 컴파일되는 코드는 Unmanaged 코드입니다.

작성자

Posted by 드리머즈

관련 글

댓글 영역