Marshal.WriteInt16 Méthode

Définition

Écrit une valeur d'entier 16 bits signé dans la mémoire non managée. L'écriture dans la mémoire non alignée est prise en charge.

Surcharges

WriteInt16(IntPtr, Char)

Écrit un caractère en tant que valeur entière 16 bits dans la mémoire non managée.

WriteInt16(IntPtr, Int16)

Écrit une valeur entière 16 bits dans la mémoire non managée.

WriteInt16(IntPtr, Int32, Char)

Écrit une valeur entière signée 16 bits dans la mémoire non managée à un offset spécifié.

WriteInt16(IntPtr, Int32, Int16)

Écrit une valeur entière signée 16 bits dans la mémoire non managée à l'offset spécifié.

WriteInt16(Object, Int32, Char)
Obsolète.

Écrit une valeur entière signée 16 bits dans la mémoire non managée à un offset spécifié.

WriteInt16(Object, Int32, Int16)
Obsolète.

Écrit une valeur entière signée 16 bits dans la mémoire non managée à un offset spécifié.

WriteInt16(IntPtr, Char)

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

Écrit un caractère en tant que valeur entière 16 bits dans la mémoire non managée.

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)

Paramètres

ptr
IntPtr

nativeint

Adresse où écrire dans la mémoire non managée.

val
Char

Valeur à écrire.

Attributs

Exceptions

ptr n'est pas un format reconnu.

- ou -

ptr a la valeur null.

- ou -

ptr n'est pas valide.

Exemples

L’exemple suivant montre comment lire et écrire dans un tableau non managé à l’aide des ReadInt16 méthodes et 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

Remarques

WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, ce qui élimine les frais liés à la copie d’un tableau non managé entier (à l’aide Marshal.Copyde ) dans un tableau managé distinct avant de définir ses valeurs d’élément.

L'écriture dans la mémoire non alignée est prise en charge.

Voir aussi

S’applique à

WriteInt16(IntPtr, Int16)

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

Écrit une valeur entière 16 bits dans la mémoire non managée.

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)

Paramètres

ptr
IntPtr

nativeint

Adresse où écrire dans la mémoire non managée.

val
Int16

Valeur à écrire.

Attributs

Exceptions

ptr n'est pas un format reconnu.

- ou -

ptr a la valeur null.

- ou -

ptr n'est pas valide.

Exemples

L’exemple suivant montre comment lire et écrire dans un tableau non managé à l’aide des ReadInt16 méthodes et 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

Remarques

WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, ce qui élimine les frais liés à la copie d’un tableau non managé entier (à l’aide Marshal.Copyde ) dans un tableau managé distinct avant de définir ses valeurs d’élément.

L'écriture dans la mémoire non alignée est prise en charge.

Voir aussi

S’applique à

WriteInt16(IntPtr, Int32, Char)

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

Écrit une valeur entière signée 16 bits dans la mémoire non managée à un offset spécifié.

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)

Paramètres

ptr
IntPtr

nativeint

Adresse de base où écrire dans le tas natif.

ofs
Int32

Offset d'octet supplémentaire, qui est ajouté au paramètre ptr avant l'écriture.

val
Char

Valeur à écrire.

Attributs

Exceptions

L'adresse de base (ptr) plus l'octet d'offset (ofs) produisent une adresse null ou non valide.

Exemples

L’exemple suivant montre comment lire et écrire dans un tableau non managé à l’aide des ReadInt16 méthodes et 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

Remarques

WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, ce qui élimine les frais liés à la copie d’un tableau non managé entier (à l’aide Marshal.Copyde ) dans un tableau managé distinct avant de définir ses valeurs d’élément.

L'écriture dans la mémoire non alignée est prise en charge.

Voir aussi

S’applique à

WriteInt16(IntPtr, Int32, Int16)

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

Écrit une valeur entière signée 16 bits dans la mémoire non managée à l'offset spécifié.

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)

Paramètres

ptr
IntPtr

nativeint

Adresse de base où écrire dans la mémoire non managée.

ofs
Int32

Offset d'octet supplémentaire, qui est ajouté au paramètre ptr avant l'écriture.

val
Int16

Valeur à écrire.

Attributs

Exceptions

L'adresse de base (ptr) plus l'octet d'offset (ofs) produisent une adresse null ou non valide.

Exemples

L’exemple suivant montre comment lire et écrire dans un tableau non managé à l’aide des ReadInt16 méthodes et 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

Remarques

WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, ce qui élimine les frais liés à la copie d’un tableau non managé entier (à l’aide Marshal.Copyde ) dans un tableau managé distinct avant de définir ses valeurs d’élément.

L'écriture dans la mémoire non alignée est prise en charge.

Voir aussi

S’applique à

WriteInt16(Object, Int32, Char)

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

Attention

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

Écrit une valeur entière signée 16 bits dans la mémoire non managée à un offset spécifié.

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)

Paramètres

ptr
Object

Adresse de base dans la mémoire non managée de l'objet cible.

ofs
Int32

Offset d'octet supplémentaire, qui est ajouté au paramètre ptr avant l'écriture.

val
Char

Valeur à écrire.

Attributs

Exceptions

L'adresse de base (ptr) plus l'octet d'offset (ofs) produisent une adresse null ou non valide.

ptr est un objet ArrayWithOffset. Cette méthode n'accepte pas les paramètres ArrayWithOffset.

Remarques

WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, ce qui élimine les frais liés à la copie d’un tableau non managé entier (à l’aide Marshal.Copyde ) dans un tableau managé distinct avant de définir ses valeurs d’élément.

L'écriture dans la mémoire non alignée est prise en charge.

Voir aussi

S’applique à

WriteInt16(Object, Int32, Int16)

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

Attention

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

Écrit une valeur entière signée 16 bits dans la mémoire non managée à un offset spécifié.

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)

Paramètres

ptr
Object

Adresse de base dans la mémoire non managée de l'objet cible.

ofs
Int32

Offset d'octet supplémentaire, qui est ajouté au paramètre ptr avant l'écriture.

val
Int16

Valeur à écrire.

Attributs

Exceptions

L'adresse de base (ptr) plus l'octet d'offset (ofs) produisent une adresse null ou non valide.

ptr est un objet ArrayWithOffset. Cette méthode n'accepte pas les paramètres ArrayWithOffset.

Remarques

WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, ce qui élimine les frais liés à la copie d’un tableau non managé entier (à l’aide Marshal.Copyde ) dans un tableau managé distinct avant de définir ses valeurs d’élément.

L'écriture dans la mémoire non alignée est prise en charge.

Voir aussi

S’applique à