Marshal.ReadByte 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
관리되지 않는 메모리에서 단일 바이트를 읽습니다. 정렬되지 않은 메모리 위치에서 읽기가 지원됩니다.
오버로드
| Name | Description |
|---|---|
| ReadByte(IntPtr, Int32) |
관리되지 않는 메모리에서 지정된 오프셋(또는 인덱스)에서 단일 바이트를 읽습니다. |
| ReadByte(Object, Int32) |
사용되지 않음.
관리되지 않는 메모리에서 지정된 오프셋(또는 인덱스)에서 단일 바이트를 읽습니다. |
| ReadByte(IntPtr) |
관리되지 않는 메모리에서 단일 바이트를 읽습니다. |
ReadByte(IntPtr, Int32)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
관리되지 않는 메모리에서 지정된 오프셋(또는 인덱스)에서 단일 바이트를 읽습니다.
public:
static System::Byte ReadByte(IntPtr ptr, int ofs);
public static byte ReadByte(IntPtr ptr, int ofs);
static member ReadByte : nativeint * int -> byte
Public Shared Function ReadByte (ptr As IntPtr, ofs As Integer) As Byte
매개 변수
- ptr
-
IntPtr
nativeint
읽을 관리되지 않는 메모리의 기본 주소입니다.
- ofs
- Int32
읽기 전에 매개 변수에 ptr 추가되는 추가 바이트 오프셋입니다.
반품
지정된 오프셋의 관리되지 않는 메모리에서 읽은 바이트입니다.
예외
기본 주소(ptr) 및 오프셋 바이트()는ofs null 또는 잘못된 주소를 생성합니다.
예제
다음 예제에서는 및 메서드를 사용하여 ReadByteWriteByte 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.
static void ReadWriteByte()
{
// Allocate unmanaged memory.
int elementSize = 1;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteByte(unmanagedArray, i * elementSize, ((Byte)(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.ReadByte(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteByte()
' Allocate unmanaged memory.
Dim elementSize As Integer = 1
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.WriteByte(unmanagedArray, i * elementSize, CType(i + 1, Byte))
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.ReadByte(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
다음 예제에서는 메서드를 사용하여 ReadByte 관리되지 않는 문자의 값을 읽는 방법을 보여 줍니다.
using namespace System;
using namespace System::Runtime::InteropServices;
void main()
{
// Create an unmanaged byte.
const char * myString = "bB";
// Read the second character of the c string as a managed byte.
Byte ^ myManagedByte = Marshal::ReadByte((IntPtr) (char *) myString, 1);
// Display the byte to the console.
Console::WriteLine(myManagedByte);
}
설명
ReadByte 를 사용하면 관리되지 않는 C 스타일 바이트 배열과 직접 상호 작용할 수 있으므로 요소 값을 읽기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 비용이 없어집니다.
정렬되지 않은 메모리 위치에서 읽기가 지원됩니다.
추가 정보
적용 대상
ReadByte(Object, Int32)
- Source:
- Marshal.CoreCLR.cs
- Source:
- Marshal.CoreCLR.cs
- Source:
- Marshal.CoreCLR.cs
- Source:
- Marshal.CoreCLR.cs
- Source:
- Marshal.CoreCLR.cs
주의
ReadByte(Object, Int32) may be unavailable in future releases.
관리되지 않는 메모리에서 지정된 오프셋(또는 인덱스)에서 단일 바이트를 읽습니다.
public:
static System::Byte ReadByte(System::Object ^ ptr, int ofs);
[System.Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static byte ReadByte(object ptr, int ofs);
[System.Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
public static byte ReadByte(object ptr, int ofs);
[System.Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")]
public static byte ReadByte(object ptr, int ofs);
public static byte ReadByte(object ptr, int ofs);
[System.Security.SecurityCritical]
public static byte ReadByte(object ptr, int ofs);
[<System.Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member ReadByte : obj * int -> byte
[<System.Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")>]
static member ReadByte : obj * int -> byte
[<System.Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")>]
static member ReadByte : obj * int -> byte
static member ReadByte : obj * int -> byte
[<System.Security.SecurityCritical>]
static member ReadByte : obj * int -> byte
Public Shared Function ReadByte (ptr As Object, ofs As Integer) As Byte
매개 변수
- ptr
- Object
원본 개체의 관리되지 않는 메모리에 있는 기본 주소입니다.
- ofs
- Int32
읽기 전에 매개 변수에 ptr 추가되는 추가 바이트 오프셋입니다.
반품
지정된 오프셋의 관리되지 않는 메모리에서 읽은 바이트입니다.
- 특성
예외
기본 주소(ptr) 및 오프셋 바이트()는ofs null 또는 잘못된 주소를 생성합니다.
ptr 는 개체입니다 ArrayWithOffset . 이 메서드는 매개 변수를 허용하지 ArrayWithOffset 않습니다.
설명
ReadByte 를 사용하면 관리되지 않는 C 스타일 바이트 배열과 직접 상호 작용할 수 있으므로 요소 값을 읽기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 비용이 없어집니다.
정렬되지 않은 메모리 위치에서 읽기가 지원됩니다.
추가 정보
적용 대상
ReadByte(IntPtr)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
관리되지 않는 메모리에서 단일 바이트를 읽습니다.
public:
static System::Byte ReadByte(IntPtr ptr);
public static byte ReadByte(IntPtr ptr);
static member ReadByte : nativeint -> byte
Public Shared Function ReadByte (ptr As IntPtr) As Byte
매개 변수
- ptr
-
IntPtr
nativeint
읽을 관리되지 않는 메모리의 주소입니다.
반품
관리되지 않는 메모리에서 읽은 바이트입니다.
예외
예제
다음 예제에서는 관리되지 않는 메모리 블록을 만들고, 비관리 메모리에 바이트를 쓰고, 관리되지 않는 메모리에서 바이트를 다시 읽은 다음, 관리되지 않는 메모리를 삭제합니다.
using System;
using System.Runtime.InteropServices;
class Example
{
static void Main(string[] args)
{
// Allocate 1 byte of unmanaged memory.
IntPtr hGlobal = Marshal.AllocHGlobal(1);
// Create a new byte.
byte b = 1;
Console.WriteLine("Byte written to unmanaged memory: " + b);
// Write the byte to unmanaged memory.
Marshal.WriteByte(hGlobal, b);
// Read byte from unmanaged memory.
byte c = Marshal.ReadByte(hGlobal);
Console.WriteLine("Byte read from unmanaged memory: " + c);
// Free the unmanaged memory.
Marshal.FreeHGlobal(hGlobal);
Console.WriteLine("Unmanaged memory was disposed.");
}
}
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Allocate 1 byte of unmanaged memory.
Dim hGlobal As IntPtr = Marshal.AllocHGlobal(1)
' Create a new byte.
Dim b As Byte = 1
Console.WriteLine("Byte written to unmanaged memory: {0}", b)
' Write the byte to unmanaged memory.
Marshal.WriteByte(hGlobal, b)
' Read byte from unmanaged memory.
Dim c As Byte = Marshal.ReadByte(hGlobal)
Console.WriteLine("Byte read from unmanaged memory: {0}", c)
' Free the unmanaged memory.
Marshal.FreeHGlobal(hGlobal)
Console.WriteLine("Unmanaged memory was disposed.")
End Sub
End Module
다음 예제에서는 메서드를 사용하여 ReadByte 관리되지 않는 문자의 값을 읽는 방법을 보여 줍니다.
using namespace System;
using namespace System::Runtime::InteropServices;
void main()
{
// Create an unmanaged byte.
const char * myString = "b";
// Read the c string as a managed byte.
Byte ^ myManagedByte = Marshal::ReadByte((IntPtr) (char *) myString);
// Display the byte to the console.
Console::WriteLine(myManagedByte);
}
설명
ReadByte 에는 암시적 오프셋이 0입니다. 이 메서드를 사용하면 관리되지 않는 C 스타일 바이트 배열과 직접 상호 작용할 수 있으므로 요소 값을 읽기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 비용이 없어집니다.
정렬되지 않은 메모리 위치에서 읽기가 지원됩니다.