■ Marshal 클래스의 Copy 정적 메소드를 사용해 바이트 배열을 비관리 메모리에 복사하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 |
using System.Runtime.InteropServices; using System.Text; byte[] sourceByteArray = Encoding.UTF8.GetBytes("안녕하세요"); IntPtr targetHandle = Marshal.AllocHGlobal(sourceByteArray.Length); Marshal.Copy(sourceByteArray, 0, targetHandle, sourceByteArray.Length); |