[C#/COMMON/.NET6] GCHandle 클래스 : AddrOfPinnedObject 메소드를 사용해 고정된 객체 데이터의 핸들 구하기
C#/Common 2022. 10. 19. 16:31728x90
반응형
728x170
■ GCHandle 클래스의 AddrOfPinnedObject 메소드를 사용해 고정된 객체 데이터의 핸들을 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
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();
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요