Marshal.WriteInt32 Méthode

Définition

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

Surcharges

WriteInt32(Object, Int32, Int32)
Obsolète.

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

WriteInt32(IntPtr, Int32)

Écrit une valeur d'entier 32 bits signé dans la mémoire non managée.

WriteInt32(IntPtr, Int32, Int32)

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

WriteInt32(Object, Int32, Int32)

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

Attention

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

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

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

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
Int32

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

WriteInt32 permet l’interaction directe avec un tableau signé 32 bits non managé, éliminant 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éments.

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

Voir aussi

S’applique à

WriteInt32(IntPtr, Int32)

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

Écrit une valeur d'entier 32 bits signé dans la mémoire non managée.

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

Paramètres

ptr
IntPtr

nativeint

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

val
Int32

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 ReadInt32 méthodes et WriteInt32 .

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

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

    Marshal.FreeHGlobal(unmanagedArray);

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

    Marshal.FreeHGlobal(unmanagedArray)

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

Remarques

WriteInt32 permet l’interaction directe avec un tableau signé 32 bits non managé, éliminant 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éments.

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

Voir aussi

S’applique à

WriteInt32(IntPtr, Int32, Int32)

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

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

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

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
Int32

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 ReadInt32 méthodes et WriteInt32 .

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

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

    Marshal.FreeHGlobal(unmanagedArray);

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

    Marshal.FreeHGlobal(unmanagedArray)

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

Remarques

WriteInt32 permet l’interaction directe avec un tableau signé 32 bits non managé, éliminant 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éments.

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

Voir aussi

S’applique à