Marshal.WriteInt16 Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Écrit une valeur entière signée 16 bits dans la mémoire non managée. L’écriture dans des emplacements de mémoire non alignés est prise en charge.
Surcharges
| Nom | Description |
|---|---|
| WriteInt16(IntPtr, Char) |
Écrit un caractère sous la forme d’une 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 décalage spécifié. |
| WriteInt16(IntPtr, Int32, Int16) |
Écrit une valeur entière signée 16 bits dans une mémoire non managée à un décalage 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 décalage 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 décalage spécifié. |
WriteInt16(IntPtr, Char)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
Écrit un caractère sous la forme d’une 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 dans la mémoire non managée dans laquelle écrire.
- 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 méthodes et ReadInt16 des WriteInt16 méthodes.
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é, éliminant ainsi les frais de copie d’un tableau non managé entier (à l’aide Marshal.Copy) dans un tableau managé distinct avant de définir ses valeurs d’élément.
L’écriture dans des emplacements de mémoire non alignés est prise en charge.
Voir aussi
S’applique à
WriteInt16(IntPtr, Int16)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- 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 dans la mémoire non managée dans laquelle écrire.
- 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 méthodes et ReadInt16 des WriteInt16 méthodes.
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é, éliminant ainsi les frais de copie d’un tableau non managé entier (à l’aide Marshal.Copy) dans un tableau managé distinct avant de définir ses valeurs d’élément.
L’écriture dans des emplacements de mémoire non alignés est prise en charge.
Voir aussi
S’applique à
WriteInt16(IntPtr, Int32, Char)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- 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 décalage 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 dans le tas natif dans lequel écrire.
- ofs
- Int32
Décalage d’octet supplémentaire, ajouté au paramètre avant l’écriture ptr .
- val
- Char
Valeur à écrire.
- Attributs
Exceptions
L’adresse de base (ptr) plus l’octet de décalage (ofs) produit une adresse null ou non valide.
Exemples
L’exemple suivant montre comment lire et écrire dans un tableau non managé à l’aide des méthodes et ReadInt16 des WriteInt16 méthodes.
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é, éliminant ainsi les frais de copie d’un tableau non managé entier (à l’aide Marshal.Copy) dans un tableau managé distinct avant de définir ses valeurs d’élément.
L’écriture dans des emplacements de mémoire non alignés est prise en charge.
Voir aussi
S’applique à
WriteInt16(IntPtr, Int32, Int16)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
Écrit une valeur entière signée 16 bits dans une mémoire non managée à un décalage 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 dans la mémoire non managée dans laquelle écrire.
- ofs
- Int32
Décalage d’octet supplémentaire, ajouté au paramètre avant l’écriture ptr .
- val
- Int16
Valeur à écrire.
- Attributs
Exceptions
L’adresse de base (ptr) plus l’octet de décalage (ofs) produit une adresse null ou non valide.
Exemples
L’exemple suivant montre comment lire et écrire dans un tableau non managé à l’aide des méthodes et ReadInt16 des WriteInt16 méthodes.
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é, éliminant ainsi les frais de copie d’un tableau non managé entier (à l’aide Marshal.Copy) dans un tableau managé distinct avant de définir ses valeurs d’élément.
L’écriture dans des emplacements de mémoire non alignés est prise en charge.
Voir aussi
S’applique à
WriteInt16(Object, Int32, Char)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- 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 décalage 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.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
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.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")>]
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 en mémoire non managée de l’objet cible.
- ofs
- Int32
Décalage d’octet supplémentaire, ajouté au paramètre avant l’écriture ptr .
- val
- Char
Valeur à écrire.
- Attributs
Exceptions
L’adresse de base (ptr) plus l’octet de décalage (ofs) produit une adresse null ou non valide.
ptr est un ArrayWithOffset objet. Cette méthode n’accepte pas les ArrayWithOffset paramètres.
Remarques
WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, éliminant ainsi les frais de copie d’un tableau non managé entier (à l’aide Marshal.Copy) dans un tableau managé distinct avant de définir ses valeurs d’élément.
L’écriture dans des emplacements de mémoire non alignés est prise en charge.
Voir aussi
S’applique à
WriteInt16(Object, Int32, Int16)
- Source:
- Marshal.CoreCLR.cs
- Source:
- Marshal.CoreCLR.cs
- 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 décalage 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.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
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.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")>]
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 en mémoire non managée de l’objet cible.
- ofs
- Int32
Décalage d’octet supplémentaire, ajouté au paramètre avant l’écriture ptr .
- val
- Int16
Valeur à écrire.
- Attributs
Exceptions
L’adresse de base (ptr) plus l’octet de décalage (ofs) produit une adresse null ou non valide.
ptr est un ArrayWithOffset objet. Cette méthode n’accepte pas les ArrayWithOffset paramètres.
Remarques
WriteInt16 permet une interaction directe avec un tableau signé 16 bits non managé, éliminant ainsi les frais de copie d’un tableau non managé entier (à l’aide Marshal.Copy) dans un tableau managé distinct avant de définir ses valeurs d’élément.
L’écriture dans des emplacements de mémoire non alignés est prise en charge.