共用方式為


Marshal.WriteInt64 方法

定義

將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體中。 支援寫入未配置的記憶體位置。

多載

WriteInt64(Object, Int32, Int64)
已淘汰.

在指定的位移,將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt64(IntPtr, Int64)

將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體中。

WriteInt64(IntPtr, Int32, Int64)

在指定的位移,將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt64(Object, Int32, Int64)

來源:
Marshal.CoreCLR.cs
來源:
Marshal.CoreCLR.cs
來源:
Marshal.CoreCLR.cs

警告

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

在指定的位移,將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體。

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

參數

ptr
Object

目標物件之 Unmanaged 記憶體中的基底位址。

ofs
Int32

額外的位元組位移,會先加入至參數 ptr,然後再進行寫入。

val
Int64

要寫入的值。

屬性

例外狀況

基底位址 (ptr) 加上位移位元組 (ofs) 會產生 Null 或無效的位址。

ptrArrayWithOffset 物件。 這個方法不會接受 ArrayWithOffset 參數。

備註

WriteInt64 可讓您與 Unmanaged 64 位帶正負號的陣列直接互動,而不需要) 在設定其元素值之前,先將 Marshal.Copy 整個 Unmanaged 陣組複製 ( (。

支援寫入未配置的記憶體位置。

另請參閱

適用於

WriteInt64(IntPtr, Int64)

來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs

將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體中。

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

參數

ptr
IntPtr

nativeint

Unmanaged 記憶體中要寫入的位址。

val
Int64

要寫入的值。

屬性

例外狀況

ptr 不是可辨認的格式。

-或-

ptrnull

-或-

ptr 無效。

範例

下列範例示範如何使用 和 WriteInt64 方法來讀取和寫入 Unmanaged 陣列ReadInt64

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

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

    Marshal.FreeHGlobal(unmanagedArray);

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

    Marshal.FreeHGlobal(unmanagedArray)

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

備註

WriteInt64 可讓您與 Unmanaged 64 位帶正負號的陣列直接互動,而不需要) 在設定其元素值之前,先將 Marshal.Copy 整個 Unmanaged 陣組複製 ( (。

支援寫入未配置的記憶體位置。

另請參閱

適用於

WriteInt64(IntPtr, Int32, Int64)

來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs

在指定的位移,將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體。

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

參數

ptr
IntPtr

nativeint

要寫入之 Unmanaged 記憶體中的基底位址。

ofs
Int32

額外的位元組位移,會先加入至參數 ptr,然後再進行寫入。

val
Int64

要寫入的值。

屬性

例外狀況

基底位址 (ptr) 加上位移位元組 (ofs) 會產生 Null 或無效的位址。

範例

下列範例示範如何使用 和 WriteInt64 方法來讀取和寫入 Unmanaged 陣列ReadInt64

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

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

    Marshal.FreeHGlobal(unmanagedArray);

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

    Marshal.FreeHGlobal(unmanagedArray)

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

備註

WriteInt64 可讓您與 Unmanaged 64 位帶正負號的陣列直接互動,而不需要) 在設定其元素值之前,先將 Marshal.Copy 整個 Unmanaged 陣組複製 ( (。

支援寫入未配置的記憶體位置。

另請參閱

適用於