Marshal.ReadIntPtr 메서드
정의
관리되지 않는 메모리에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native sized integer from unmanaged memory. 정렬되지 않은 메모리 위치에서 읽을 수 있습니다.Reading from unaligned memory locations is supported.
오버로드
ReadIntPtr(IntPtr, Int32) |
관리되지 않는 메모리의 지정된 오프셋 위치에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native sized integer at a given offset from unmanaged memory. |
ReadIntPtr(Object, Int32) |
사용되지 않습니다.
관리되지 않는 메모리에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native sized integer from unmanaged memory. |
ReadIntPtr(IntPtr) |
관리되지 않는 메모리에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native-sized integer from unmanaged memory. |
ReadIntPtr(IntPtr, Int32)
관리되지 않는 메모리의 지정된 오프셋 위치에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native sized integer at a given offset from unmanaged memory.
public:
static IntPtr ReadIntPtr(IntPtr ptr, int ofs);
[System.Security.SecurityCritical]
public static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
public static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
[<System.Security.SecurityCritical>]
static member ReadIntPtr : nativeint * int -> nativeint
static member ReadIntPtr : nativeint * int -> nativeint
Public Shared Function ReadIntPtr (ptr As IntPtr, ofs As Integer) As IntPtr
매개 변수
- ptr
- IntPtr
읽을 관리되지 않는 메모리의 기본 주소입니다.The base address in unmanaged memory from which to read.
- ofs
- Int32
읽기 전에 ptr
매개 변수에 추가되는 추가 바이트 오프셋입니다.An additional byte offset, which is added to the ptr
parameter before reading.
반환
관리되지 않는 메모리의 지정된 오프셋 위치에서 읽은 정수입니다.The integer read from unmanaged memory at the given offset.
- 특성
예외
기준 주소(ptr
)에 오프셋 바이트(ofs
)를 더하면 null 또는 잘못된 주소가 생성되는 경우Base address (ptr
) plus offset byte (ofs
) produces a null or invalid address.
예제
다음 예제에서는 및 메서드를 사용 하 여 관리 되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다 ReadIntPtr WriteIntPtr .The following example demonstrates how to read and write to an unmanaged array using the ReadIntPtr and WriteIntPtr methods.
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
설명
ReadIntPtr 관리 되지 않는 C 스타일 배열과 직접 상호 작용 하 여 IntPtr
해당 요소 값을 읽기 전에 관리 되지 않는 전체 배열 (사용 Marshal.Copy )을 별도의 관리 되는 배열에 복사 하는 비용을 없앨 수 있습니다.ReadIntPtr enables direct interaction with an unmanaged C-style IntPtr
array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before reading its element values.
정렬되지 않은 메모리 위치에서 읽을 수 있습니다.Reading from unaligned memory locations is supported.
추가 정보
적용 대상
ReadIntPtr(Object, Int32)
주의
ReadIntPtr(Object, Int32) may be unavailable in future releases.
관리되지 않는 메모리에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native sized integer from unmanaged memory.
public:
static IntPtr ReadIntPtr(System::Object ^ ptr, int ofs);
[System.Obsolete("ReadIntPtr(Object, Int32) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static IntPtr ReadIntPtr (object ptr, int ofs);
[System.Obsolete("ReadIntPtr(Object, Int32) may be unavailable in future releases.")]
public static IntPtr ReadIntPtr (object ptr, int ofs);
public static IntPtr ReadIntPtr (object ptr, int ofs);
[System.Security.SecurityCritical]
public static IntPtr ReadIntPtr (object ptr, int ofs);
[<System.Obsolete("ReadIntPtr(Object, Int32) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member ReadIntPtr : obj * int -> nativeint
[<System.Obsolete("ReadIntPtr(Object, Int32) may be unavailable in future releases.")>]
static member ReadIntPtr : obj * int -> nativeint
static member ReadIntPtr : obj * int -> nativeint
[<System.Security.SecurityCritical>]
static member ReadIntPtr : obj * int -> nativeint
Public Shared Function ReadIntPtr (ptr As Object, ofs As Integer) As IntPtr
매개 변수
- ptr
- Object
소스 개체에 대한 관리되지 않는 메모리의 기본 주소입니다.The base address in unmanaged memory of the source object.
- ofs
- Int32
읽기 전에 ptr
매개 변수에 추가되는 추가 바이트 오프셋입니다.An additional byte offset, which is added to the ptr
parameter before reading.
반환
관리되지 않는 메모리의 지정된 오프셋 위치에서 읽은 정수입니다.The integer read from unmanaged memory at the given offset.
- 특성
예외
기준 주소(ptr
)에 오프셋 바이트(ofs
)를 더하면 null 또는 잘못된 주소가 생성되는 경우Base address (ptr
) plus offset byte (ofs
) produces a null or invalid address.
ptr
이 ArrayWithOffset 개체인 경우.ptr
is an ArrayWithOffset object. 이 메서드에는 ArrayWithOffset 매개 변수를 사용할 수 없습니다.This method does not accept ArrayWithOffset parameters.
설명
ReadIntPtr 관리 되지 않는 C 스타일 배열과 직접 상호 작용 하 여 IntPtr
해당 요소 값을 읽기 전에 관리 되지 않는 전체 배열 (사용 Marshal.Copy )을 별도의 관리 되는 배열에 복사 하는 비용을 없앨 수 있습니다.ReadIntPtr enables direct interaction with an unmanaged C-style IntPtr
array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before reading its element values.
정렬되지 않은 메모리 위치에서 읽을 수 있습니다.Reading from unaligned memory locations is supported.
추가 정보
적용 대상
ReadIntPtr(IntPtr)
관리되지 않는 메모리에서 프로세서의 기본 크기로 지정된 정수를 읽습니다.Reads a processor native-sized integer from unmanaged memory.
public:
static IntPtr ReadIntPtr(IntPtr ptr);
[System.Security.SecurityCritical]
public static IntPtr ReadIntPtr (IntPtr ptr);
public static IntPtr ReadIntPtr (IntPtr ptr);
[<System.Security.SecurityCritical>]
static member ReadIntPtr : nativeint -> nativeint
static member ReadIntPtr : nativeint -> nativeint
Public Shared Function ReadIntPtr (ptr As IntPtr) As IntPtr
매개 변수
- ptr
- IntPtr
읽을 관리되지 않는 메모리의 주소입니다.The address in unmanaged memory from which to read.
반환
관리되지 않는 메모리에서 읽은 정수입니다.The integer read from unmanaged memory. 32비트 컴퓨터에서는 32비트 정수가 반환되고 64비트 컴퓨터에서는 64비트 정수가 반환됩니다.A 32 bit integer is returned on 32 bit machines and a 64 bit integer is returned on 64 bit machines.
- 특성
예외
ptr
의 형식을 인식할 수 없는 경우ptr
is not a recognized format.
또는-or-
ptr
은 null
입니다.ptr
is null
.
또는-or-
ptr
이 잘못되었습니다.ptr
is invalid.
예제
다음 예제에서는 및 메서드를 사용 하 여 관리 되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다 ReadIntPtr WriteIntPtr .The following example demonstrates how to read and write to an unmanaged array using the ReadIntPtr and WriteIntPtr methods.
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
설명
ReadIntPtr 의 암시적 오프셋이 0 인 경우ReadIntPtr has an implied offset of 0. 이 메서드를 사용 하면 관리 되지 않는 C 스타일 배열과 직접 상호 작용 하 IntPtr
여 해당 요소 값을 읽기 전에 관리 되지 않는 전체 배열 (사용 Marshal.Copy )을 별도의 관리 되는 배열에 복사 하는 비용을 없앨 수 있습니다.This method enables direct interaction with an unmanaged C-style IntPtr
array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before reading its element values.
정렬되지 않은 메모리 위치에서 읽을 수 있습니다.Reading from unaligned memory locations is supported.