Marshal.WriteInt16 Método

Definição

Escreve um valor inteiro assinado de 16 bits em memória não gerida. A escrita em locais de memória desalinhados é suportada.

Sobrecargas

Name Description
WriteInt16(IntPtr, Char)

Escreve um carácter como um valor inteiro de 16 bits na memória não gerida.

WriteInt16(IntPtr, Int16)

Escreve um valor inteiro de 16 bits na memória não gerida.

WriteInt16(IntPtr, Int32, Char)

Escreve um valor inteiro assinado de 16 bits em memória não gerida a um deslocamento especificado.

WriteInt16(IntPtr, Int32, Int16)

Escreve um valor inteiro assinado de 16 bits na memória não gerida a um deslocamento especificado.

WriteInt16(Object, Int32, Char)
Obsoleto.

Escreve um valor inteiro assinado de 16 bits em memória não gerida a um deslocamento especificado.

WriteInt16(Object, Int32, Int16)
Obsoleto.

Escreve um valor inteiro assinado de 16 bits em memória não gerida a um deslocamento especificado.

WriteInt16(IntPtr, Char)

Escreve um carácter como um valor inteiro de 16 bits na memória não gerida.

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)

Parâmetros

ptr
IntPtr

nativeint

O endereço na memória não gerida para escrever.

val
Char

O valor a escrever.

Atributos

Exceções

ptr não é um formato reconhecido.

-ou-

ptr é null.

-ou-

ptr é inválido.

Exemplos

O exemplo seguinte demonstra como ler e escrever num array não gerido usando os ReadInt16 métodos e.WriteInt16

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

Observações

WriteInt16 permite a interação direta com um array de assinatura não gerido de 16 bits, eliminando o custo de copiar um array inteiro não gerido (usando Marshal.Copy) para um array gerido separado antes de definir os seus valores de elementos.

A escrita em locais de memória desalinhados é suportada.

Ver também

Aplica-se a

WriteInt16(IntPtr, Int16)

Escreve um valor inteiro de 16 bits na memória não gerida.

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)

Parâmetros

ptr
IntPtr

nativeint

O endereço na memória não gerida para escrever.

val
Int16

O valor a escrever.

Atributos

Exceções

ptr não é um formato reconhecido.

-ou-

ptr é null.

-ou-

ptr é inválido.

Exemplos

O exemplo seguinte demonstra como ler e escrever num array não gerido usando os ReadInt16 métodos e.WriteInt16

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

Observações

WriteInt16 permite a interação direta com um array de assinatura não gerido de 16 bits, eliminando o custo de copiar um array inteiro não gerido (usando Marshal.Copy) para um array gerido separado antes de definir os seus valores de elementos.

A escrita em locais de memória desalinhados é suportada.

Ver também

Aplica-se a

WriteInt16(IntPtr, Int32, Char)

Escreve um valor inteiro assinado de 16 bits em memória não gerida a um deslocamento especificado.

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)

Parâmetros

ptr
IntPtr

nativeint

O endereço base no heap nativo para escrever.

ofs
Int32

Um deslocamento adicional de byte, que é adicionado ao ptr parâmetro antes da escrita.

val
Char

O valor a escrever.

Atributos

Exceções

O endereço base (ptr) mais o byte offset (ofs) produz um endereço nulo ou inválido.

Exemplos

O exemplo seguinte demonstra como ler e escrever num array não gerido usando os ReadInt16 métodos e.WriteInt16

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

Observações

WriteInt16 permite a interação direta com um array de assinatura não gerido de 16 bits, eliminando o custo de copiar um array inteiro não gerido (usando Marshal.Copy) para um array gerido separado antes de definir os seus valores de elementos.

A escrita em locais de memória desalinhados é suportada.

Ver também

Aplica-se a

WriteInt16(IntPtr, Int32, Int16)

Escreve um valor inteiro assinado de 16 bits na memória não gerida a um deslocamento especificado.

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)

Parâmetros

ptr
IntPtr

nativeint

O endereço base na memória não gerida para escrever.

ofs
Int32

Um deslocamento adicional de byte, que é adicionado ao ptr parâmetro antes da escrita.

val
Int16

O valor a escrever.

Atributos

Exceções

O endereço base (ptr) mais o byte offset (ofs) produz um endereço nulo ou inválido.

Exemplos

O exemplo seguinte demonstra como ler e escrever num array não gerido usando os ReadInt16 métodos e.WriteInt16

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

Observações

WriteInt16 permite a interação direta com um array de assinatura não gerido de 16 bits, eliminando o custo de copiar um array inteiro não gerido (usando Marshal.Copy) para um array gerido separado antes de definir os seus valores de elementos.

A escrita em locais de memória desalinhados é suportada.

Ver também

Aplica-se a

WriteInt16(Object, Int32, Char)

Atenção

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

Escreve um valor inteiro assinado de 16 bits em memória não gerida a um deslocamento especificado.

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);
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.")]
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
static member WriteInt16 : obj * int * char -> unit
[<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
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Char)

Parâmetros

ptr
Object

O endereço base na memória não gerida do objeto alvo.

ofs
Int32

Um deslocamento adicional de byte, que é adicionado ao ptr parâmetro antes da escrita.

val
Char

O valor a escrever.

Atributos

Exceções

O endereço base (ptr) mais o byte offset (ofs) produz um endereço nulo ou inválido.

ptr é um ArrayWithOffset objeto. Este método não aceita ArrayWithOffset parâmetros.

Observações

WriteInt16 permite a interação direta com um array de assinatura não gerido de 16 bits, eliminando o custo de copiar um array inteiro não gerido (usando Marshal.Copy) para um array gerido separado antes de definir os seus valores de elementos.

A escrita em locais de memória desalinhados é suportada.

Ver também

Aplica-se a

WriteInt16(Object, Int32, Int16)

Atenção

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

Escreve um valor inteiro assinado de 16 bits em memória não gerida a um deslocamento especificado.

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);
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.")]
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
static member WriteInt16 : obj * int * int16 -> unit
[<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
Public Shared Sub WriteInt16 (ptr As Object, ofs As Integer, val As Short)

Parâmetros

ptr
Object

O endereço base na memória não gerida do objeto alvo.

ofs
Int32

Um deslocamento adicional de byte, que é adicionado ao ptr parâmetro antes da escrita.

val
Int16

O valor a escrever.

Atributos

Exceções

O endereço base (ptr) mais o byte offset (ofs) produz um endereço nulo ou inválido.

ptr é um ArrayWithOffset objeto. Este método não aceita ArrayWithOffset parâmetros.

Observações

WriteInt16 permite a interação direta com um array de assinatura não gerido de 16 bits, eliminando o custo de copiar um array inteiro não gerido (usando Marshal.Copy) para um array gerido separado antes de definir os seus valores de elementos.

A escrita em locais de memória desalinhados é suportada.

Ver também

Aplica-se a