■ GCHandle 클래스의 AddrOfPinnedObject 메소드를 사용해 고정된 객체 데이터의 핸들을 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
using System.Runtime.InteropServices; using System.Text; byte[] sourceByteArray = Encoding.UTF8.GetBytes("안녕하세요"); GCHandle targetGCHandle = GCHandle.Alloc(sourceByteArray, GCHandleType.Pinned); IntPtr targetHandle = targetGCHandle.AddrOfPinnedObject(); string target = Marshal.PtrToStringUTF8(targetHandle); Console.WriteLine(target); targetGCHandle.Free(); |