Marshal.WriteIntPtr 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
프로세서 네이티브 크기의 정수 값을 관리되지 않는 메모리에 씁니다. 32비트 정수는 32비트 시스템에 기록되고 64비트 정수는 64비트 시스템에 기록됩니다. 정렬되지 않은 메모리 위치에 쓰기가 지원됩니다.
오버로드
| Name | Description |
|---|---|
| WriteIntPtr(IntPtr, IntPtr) |
프로세서 네이티브 크기의 정수 값을 관리되지 않는 메모리에 씁니다. |
| WriteIntPtr(IntPtr, Int32, IntPtr) |
지정된 오프셋에서 관리되지 않는 메모리에 프로세서 네이티브 크기의 정수 값을 씁니다. |
| WriteIntPtr(Object, Int32, IntPtr) |
사용되지 않음.
프로세서 네이티브 크기의 정수 값을 관리되지 않는 메모리에 씁니다. |
WriteIntPtr(IntPtr, IntPtr)
프로세서 네이티브 크기의 정수 값을 관리되지 않는 메모리에 씁니다.
public:
static void WriteIntPtr(IntPtr ptr, IntPtr val);
[System.Security.SecurityCritical]
public static void WriteIntPtr(IntPtr ptr, IntPtr val);
public static void WriteIntPtr(IntPtr ptr, IntPtr val);
[<System.Security.SecurityCritical>]
static member WriteIntPtr : nativeint * nativeint -> unit
static member WriteIntPtr : nativeint * nativeint -> unit
Public Shared Sub WriteIntPtr (ptr As IntPtr, val As IntPtr)
매개 변수
- ptr
-
IntPtr
nativeint
쓸 관리되지 않는 메모리의 주소입니다.
- val
-
IntPtr
nativeint
쓸 값입니다.
- 특성
예외
예제
다음 예제에서는 및 메서드를 사용하여 ReadIntPtrWriteIntPtr 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.
static void ReadWriteIntPtr()
{
// Allocate unmanaged memory.
int elementSize = Marshal.SizeOf(typeof(IntPtr));
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteIntPtr(unmanagedArray, i * elementSize, ((IntPtr)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadIntPtr(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteIntPtr()
' Allocate unmanaged memory.
Dim elementSize As Integer = Marshal.SizeOf(GetType(IntPtr))
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteIntPtr(unmanagedArray, i * elementSize, CType(i + 1, IntPtr))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadIntPtr(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
설명
WriteIntPtr 를 사용하면 관리되지 않는 C 스타일 IntPtr 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 비용이 없어집니다.
정렬되지 않은 메모리 위치에 쓰기가 지원됩니다.
추가 정보
적용 대상
WriteIntPtr(IntPtr, Int32, IntPtr)
지정된 오프셋에서 관리되지 않는 메모리에 프로세서 네이티브 크기의 정수 값을 씁니다.
public:
static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val);
[System.Security.SecurityCritical]
public static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val);
public static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val);
[<System.Security.SecurityCritical>]
static member WriteIntPtr : nativeint * int * nativeint -> unit
static member WriteIntPtr : nativeint * int * nativeint -> unit
Public Shared Sub WriteIntPtr (ptr As IntPtr, ofs As Integer, val As IntPtr)
매개 변수
- ptr
-
IntPtr
nativeint
쓸 관리되지 않는 메모리의 기본 주소입니다.
- ofs
- Int32
쓰기 전에 매개 변수에 ptr 추가되는 추가 바이트 오프셋입니다.
- val
-
IntPtr
nativeint
쓸 값입니다.
- 특성
예외
기본 주소(ptr) 및 오프셋 바이트()는ofs null 또는 잘못된 주소를 생성합니다.
예제
다음 예제에서는 및 메서드를 사용하여 ReadIntPtrWriteIntPtr 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.
static void ReadWriteIntPtr()
{
// Allocate unmanaged memory.
int elementSize = Marshal.SizeOf(typeof(IntPtr));
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteIntPtr(unmanagedArray, i * elementSize, ((IntPtr)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadIntPtr(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteIntPtr()
' Allocate unmanaged memory.
Dim elementSize As Integer = Marshal.SizeOf(GetType(IntPtr))
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteIntPtr(unmanagedArray, i * elementSize, CType(i + 1, IntPtr))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadIntPtr(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
설명
이 메서드는 32비트 시스템에 32비트 정수, 64비트 시스템에서는 64비트 정수로 작성합니다.
WriteIntPtr 를 사용하면 관리되지 않는 C 스타일 IntPtr 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 비용이 없어집니다.
정렬되지 않은 메모리 위치에 쓰기가 지원됩니다.
추가 정보
적용 대상
WriteIntPtr(Object, Int32, IntPtr)
주의
WriteIntPtr(Object, Int32, IntPtr) may be unavailable in future releases.
프로세서 네이티브 크기의 정수 값을 관리되지 않는 메모리에 씁니다.
public:
static void WriteIntPtr(System::Object ^ ptr, int ofs, IntPtr val);
[System.Obsolete("WriteIntPtr(Object, Int32, IntPtr) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteIntPtr(object ptr, int ofs, IntPtr val);
public static void WriteIntPtr(object ptr, int ofs, IntPtr val);
[System.Security.SecurityCritical]
public static void WriteIntPtr(object ptr, int ofs, IntPtr val);
[System.Obsolete("WriteIntPtr(Object, Int32, IntPtr) may be unavailable in future releases.")]
public static void WriteIntPtr(object ptr, int ofs, IntPtr val);
[<System.Obsolete("WriteIntPtr(Object, Int32, IntPtr) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteIntPtr : obj * int * nativeint -> unit
static member WriteIntPtr : obj * int * nativeint -> unit
[<System.Security.SecurityCritical>]
static member WriteIntPtr : obj * int * nativeint -> unit
[<System.Obsolete("WriteIntPtr(Object, Int32, IntPtr) may be unavailable in future releases.")>]
static member WriteIntPtr : obj * int * nativeint -> unit
Public Shared Sub WriteIntPtr (ptr As Object, ofs As Integer, val As IntPtr)
매개 변수
- ptr
- Object
대상 개체의 관리되지 않는 메모리에 있는 기본 주소입니다.
- ofs
- Int32
쓰기 전에 매개 변수에 ptr 추가되는 추가 바이트 오프셋입니다.
- val
-
IntPtr
nativeint
쓸 값입니다.
- 특성
예외
기본 주소(ptr) 및 오프셋 바이트()는ofs null 또는 잘못된 주소를 생성합니다.
ptr 는 개체입니다 ArrayWithOffset . 이 메서드는 매개 변수를 허용하지 ArrayWithOffset 않습니다.
설명
WriteIntPtr 를 사용하면 관리되지 않는 C 스타일 바이트 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 비용이 없어집니다.
정렬되지 않은 메모리 위치에 쓰기가 지원됩니다.