Marshal.WriteInt16 메서드

정의

관리되지 않는 메모리에 부호 있는 16비트 정수 값을 씁니다. 정렬되지 않은 메모리 위치에 쓸 수 있습니다.

오버로드

WriteInt16(IntPtr, Char)

관리되지 않는 메모리에 16비트 정수 값으로 문자를 씁니다.

WriteInt16(IntPtr, Int16)

관리되지 않는 메모리에 16비트 정수 값을 씁니다.

WriteInt16(IntPtr, Int32, Char)

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

WriteInt16(IntPtr, Int32, Int16)

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

WriteInt16(Object, Int32, Char)
사용되지 않음.

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

WriteInt16(Object, Int32, Int16)
사용되지 않음.

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

WriteInt16(IntPtr, Char)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

관리되지 않는 메모리에 16비트 정수 값으로 문자를 씁니다.

public:
 static void WriteInt16(IntPtr ptr, char val);
[System.Security.SecurityCritical]
public static void WriteInt16 (IntPtr ptr, char val);
public static void WriteInt16 (IntPtr ptr, char val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * char -> unit
static member WriteInt16 : nativeint * char -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, val As Char)

매개 변수

ptr
IntPtr

nativeint

관리되지 않는 메모리에서 값을 쓸 주소입니다.

val
Char

작성할 값입니다.

특성

예외

ptr의 형식을 인식할 수 없는 경우

또는

ptrnull입니다.

또는

ptr이 잘못되었습니다.

예제

다음 예제에서는 및 WriteInt16 메서드를 사용하여 ReadInt16 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(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.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    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.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    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.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

설명

WriteInt16 를 사용하면 관리되지 않는 16비트 부호 있는 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 데 드는 비용이 제거됩니다.

정렬되지 않은 메모리 위치에 쓸 수 있습니다.

추가 정보

적용 대상

WriteInt16(IntPtr, Int16)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

관리되지 않는 메모리에 16비트 정수 값을 씁니다.

public:
 static void WriteInt16(IntPtr ptr, short val);
[System.Security.SecurityCritical]
public static void WriteInt16 (IntPtr ptr, short val);
public static void WriteInt16 (IntPtr ptr, short val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int16 -> unit
static member WriteInt16 : nativeint * int16 -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, val As Short)

매개 변수

ptr
IntPtr

nativeint

관리되지 않는 메모리에서 값을 쓸 주소입니다.

val
Int16

작성할 값입니다.

특성

예외

ptr의 형식을 인식할 수 없는 경우

또는

ptrnull입니다.

또는

ptr이 잘못되었습니다.

예제

다음 예제에서는 및 WriteInt16 메서드를 사용하여 ReadInt16 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(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.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    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.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    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.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

설명

WriteInt16 를 사용하면 관리되지 않는 16비트 부호 있는 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 데 드는 비용이 제거됩니다.

정렬되지 않은 메모리 위치에 쓸 수 있습니다.

추가 정보

적용 대상

WriteInt16(IntPtr, Int32, Char)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

public:
 static void WriteInt16(IntPtr ptr, int ofs, char val);
[System.Security.SecurityCritical]
public static void WriteInt16 (IntPtr ptr, int ofs, char val);
public static void WriteInt16 (IntPtr ptr, int ofs, char val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int * char -> unit
static member WriteInt16 : nativeint * int * char -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, ofs As Integer, val As Char)

매개 변수

ptr
IntPtr

nativeint

네이티브 힙에서 값을 쓸 기본 주소입니다.

ofs
Int32

쓰기 전에 ptr 매개 변수에 추가되는 추가 바이트 오프셋입니다.

val
Char

작성할 값입니다.

특성

예외

기준 주소(ptr)에 오프셋 바이트(ofs)를 더하면 null 또는 잘못된 주소가 생성되는 경우

예제

다음 예제에서는 및 WriteInt16 메서드를 사용하여 ReadInt16 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(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.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    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.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    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.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

설명

WriteInt16 를 사용하면 관리되지 않는 16비트 부호 있는 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 데 드는 비용이 제거됩니다.

정렬되지 않은 메모리 위치에 쓸 수 있습니다.

추가 정보

적용 대상

WriteInt16(IntPtr, Int32, Int16)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

public:
 static void WriteInt16(IntPtr ptr, int ofs, short val);
[System.Security.SecurityCritical]
public static void WriteInt16 (IntPtr ptr, int ofs, short val);
public static void WriteInt16 (IntPtr ptr, int ofs, short val);
[<System.Security.SecurityCritical>]
static member WriteInt16 : nativeint * int * int16 -> unit
static member WriteInt16 : nativeint * int * int16 -> unit
Public Shared Sub WriteInt16 (ptr As IntPtr, ofs As Integer, val As Short)

매개 변수

ptr
IntPtr

nativeint

관리되지 않는 메모리에서 값을 쓸 기본 주소입니다.

ofs
Int32

쓰기 전에 ptr 매개 변수에 추가되는 추가 바이트 오프셋입니다.

val
Int16

작성할 값입니다.

특성

예외

기준 주소(ptr)에 오프셋 바이트(ofs)를 더하면 null 또는 잘못된 주소가 생성되는 경우

예제

다음 예제에서는 및 WriteInt16 메서드를 사용하여 ReadInt16 관리되지 않는 배열을 읽고 쓰는 방법을 보여 줍니다.

static void ReadWriteInt16()
{
    // Allocate unmanaged memory. 
    int elementSize = 2;
    IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);

    // Set the 10 elements of the C-style unmanagedArray
    for (int i = 0; i < 10; i++)
    {
        Marshal.WriteInt16(unmanagedArray, i * elementSize, ((Int16)(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.ReadInt16(unmanagedArray, i * elementSize));
    }

    Marshal.FreeHGlobal(unmanagedArray);

    Console.WriteLine("Done. Press Enter to continue.");
    Console.ReadLine();
}
Sub ReadWriteInt16()
    ' Allocate unmanaged memory. 
    Dim elementSize As Integer = 2
    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.WriteInt16(unmanagedArray, i * elementSize, CType(i + 1, Int16))
    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.ReadInt16(unmanagedArray, i * elementSize))
    Next i

    Marshal.FreeHGlobal(unmanagedArray)

    Console.WriteLine("Done. Press Enter to continue.")
    Console.ReadLine()
End Sub

설명

WriteInt16 를 사용하면 관리되지 않는 16비트 부호 있는 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 데 드는 비용이 제거됩니다.

정렬되지 않은 메모리 위치에 쓸 수 있습니다.

추가 정보

적용 대상

WriteInt16(Object, Int32, Char)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

주의

WriteInt16(Object, Int32, Char) may be unavailable in future releases.

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

public:
 static void WriteInt16(System::Object ^ ptr, int ofs, char val);
[System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteInt16 (object ptr, int ofs, char val);
[System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
public static void WriteInt16 (object ptr, int ofs, char val);
public static void WriteInt16 (object ptr, int ofs, char val);
[System.Security.SecurityCritical]
public static void WriteInt16 (object ptr, int ofs, char val);
[<System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * char -> unit
[<System.Obsolete("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")>]
static member WriteInt16 : obj * int * char -> unit
static member WriteInt16 : obj * int * char -> unit
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * char -> unit
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Char)

매개 변수

ptr
Object

대상 개체에 대한 관리되지 않는 메모리의 기본 주소입니다.

ofs
Int32

쓰기 전에 ptr 매개 변수에 추가되는 추가 바이트 오프셋입니다.

val
Char

작성할 값입니다.

특성

예외

기준 주소(ptr)에 오프셋 바이트(ofs)를 더하면 null 또는 잘못된 주소가 생성되는 경우

ptrArrayWithOffset 개체인 경우. 이 메서드에는 ArrayWithOffset 매개 변수를 사용할 수 없습니다.

설명

WriteInt16 를 사용하면 관리되지 않는 16비트 부호 있는 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 데 드는 비용이 제거됩니다.

정렬되지 않은 메모리 위치에 쓸 수 있습니다.

추가 정보

적용 대상

WriteInt16(Object, Int32, Int16)

Source:
Marshal.CoreCLR.cs
Source:
Marshal.CoreCLR.cs
Source:
Marshal.CoreCLR.cs

주의

WriteInt16(Object, Int32, Int16) may be unavailable in future releases.

관리되지 않는 메모리의 지정된 오프셋 위치에 16비트 부호 있는 정수 값을 씁니다.

public:
 static void WriteInt16(System::Object ^ ptr, int ofs, short val);
[System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteInt16 (object ptr, int ofs, short val);
[System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
public static void WriteInt16 (object ptr, int ofs, short val);
public static void WriteInt16 (object ptr, int ofs, short val);
[System.Security.SecurityCritical]
public static void WriteInt16 (object ptr, int ofs, short val);
[<System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * int16 -> unit
[<System.Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")>]
static member WriteInt16 : obj * int * int16 -> unit
static member WriteInt16 : obj * int * int16 -> unit
[<System.Security.SecurityCritical>]
static member WriteInt16 : obj * int * int16 -> unit
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Short)

매개 변수

ptr
Object

대상 개체에 대한 관리되지 않는 메모리의 기본 주소입니다.

ofs
Int32

쓰기 전에 ptr 매개 변수에 추가되는 추가 바이트 오프셋입니다.

val
Int16

작성할 값입니다.

특성

예외

기준 주소(ptr)에 오프셋 바이트(ofs)를 더하면 null 또는 잘못된 주소가 생성되는 경우

ptrArrayWithOffset 개체인 경우. 이 메서드에는 ArrayWithOffset 매개 변수를 사용할 수 없습니다.

설명

WriteInt16 를 사용하면 관리되지 않는 16비트 부호 있는 배열과 직접 상호 작용할 수 있으므로 요소 값을 설정하기 전에 관리되지 않는 전체 배열(사용 Marshal.Copy)을 별도의 관리형 배열에 복사하는 데 드는 비용이 제거됩니다.

정렬되지 않은 메모리 위치에 쓸 수 있습니다.

추가 정보

적용 대상