Marshal.WriteInt32 Metodo

Definizione

Scrive un valore intero con segno a 32 bit nella memoria non gestita. La scrittura in percorsi di memoria non allineati è supportata.

Overload

Nome Descrizione
WriteInt32(Object, Int32, Int32)
Obsoleti.

Scrive un valore intero con segno a 32 bit nella memoria non gestita in corrispondenza di un offset specificato.

WriteInt32(IntPtr, Int32)

Scrive un valore intero con segno a 32 bit nella memoria non gestita.

WriteInt32(IntPtr, Int32, Int32)

Scrive un valore intero con segno a 32 bit nella memoria non gestita in corrispondenza di un offset specificato.

WriteInt32(Object, Int32, Int32)

Origine:
Marshal.CoreCLR.cs
Origine:
Marshal.CoreCLR.cs
Origine:
Marshal.CoreCLR.cs
Origine:
Marshal.CoreCLR.cs
Origine:
Marshal.CoreCLR.cs

Attenzione

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

Scrive un valore intero con segno a 32 bit nella memoria non gestita in corrispondenza di un offset specificato.

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.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
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.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")>]
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)

Parametri

ptr
Object

Indirizzo di base nella memoria non gestita dell'oggetto di destinazione.

ofs
Int32

Offset di byte aggiuntivo, che viene aggiunto al parametro prima della ptr scrittura.

val
Int32

Valore da scrivere.

Attributi

Eccezioni

L'indirizzo di base (ptr) più byte offset (ofs) produce un indirizzo Null o non valido.

ptr è un ArrayWithOffset oggetto . Questo metodo non accetta ArrayWithOffset parametri.

Commenti

WriteInt32 consente l'interazione diretta con una matrice con segno a 32 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostare i relativi valori di elemento.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt32(IntPtr, Int32)

Origine:
Marshal.cs
Origine:
Marshal.cs
Origine:
Marshal.cs
Origine:
Marshal.cs
Origine:
Marshal.cs

Scrive un valore intero con segno a 32 bit nella memoria non gestita.

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)

Parametri

ptr
IntPtr

nativeint

Indirizzo in memoria non gestita in cui scrivere.

val
Int32

Valore da scrivere.

Attributi

Eccezioni

ptr non è un formato riconosciuto.

oppure

ptr è null.

oppure

ptr non è valido.

Esempio

Nell'esempio seguente viene illustrato come leggere e scrivere in una matrice non gestita usando i ReadInt32 metodi e 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

Commenti

WriteInt32 consente l'interazione diretta con una matrice con segno a 32 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostare i relativi valori di elemento.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a

WriteInt32(IntPtr, Int32, Int32)

Origine:
Marshal.cs
Origine:
Marshal.cs
Origine:
Marshal.cs
Origine:
Marshal.cs
Origine:
Marshal.cs

Scrive un valore intero con segno a 32 bit nella memoria non gestita in corrispondenza di un offset specificato.

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)

Parametri

ptr
IntPtr

nativeint

Indirizzo di base nella memoria non gestita in cui scrivere.

ofs
Int32

Offset di byte aggiuntivo, che viene aggiunto al parametro prima della ptr scrittura.

val
Int32

Valore da scrivere.

Attributi

Eccezioni

L'indirizzo di base (ptr) più byte offset (ofs) produce un indirizzo Null o non valido.

Esempio

Nell'esempio seguente viene illustrato come leggere e scrivere in una matrice non gestita usando i ReadInt32 metodi e 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

Commenti

WriteInt32 consente l'interazione diretta con una matrice con segno a 32 bit non gestita, eliminando i costi di copia di un'intera matrice non gestita (usando Marshal.Copy) in una matrice gestita separata prima di impostare i relativi valori di elemento.

La scrittura in percorsi di memoria non allineati è supportata.

Vedi anche

Si applica a