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