Marshal.WriteInt64 方法
定义
将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory. 支持写入未对齐的内存位置。Writing to unaligned memory locations is supported.
重载
| WriteInt64(Object, Int32, Int64) |
已过时。
按指定偏移量将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory at a specified offset. |
| WriteInt64(IntPtr, Int64) |
将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory. |
| WriteInt64(IntPtr, Int32, Int64) |
按指定偏移量将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory at a specified offset. |
WriteInt64(Object, Int32, Int64)
注意
WriteInt64(Object, Int32, Int64) may be unavailable in future releases.
按指定偏移量将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory at a specified offset.
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
非托管内存中目标对象的基址。The base address in unmanaged memory of the target object.
- ofs
- Int32
额外的字节偏移量,在写入前添加到 ptr 参数中。An additional byte offset, which is added to the ptr parameter before writing.
- val
- Int64
要写入的值。The value to write.
- 属性
例外
基址 (ptr) 加上偏移字节 (ofs) 可产生空或无效地址。Base address (ptr) plus offset byte (ofs) produces a null or invalid address.
ptr 是 ArrayWithOffset 对象。ptr is an ArrayWithOffset object. 此方法不接受 ArrayWithOffset 参数。This method does not accept ArrayWithOffset parameters.
注解
WriteInt64 实现与非托管64位已签名数组的直接交互,消除在 Marshal.Copy 设置其元素值之前使用) 将整个非托管数组复制 (的代价。WriteInt64 enables direct interaction with an unmanaged 64-bit signed array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before setting its element values.
支持写入未对齐的内存位置。Writing to unaligned memory locations is supported.
另请参阅
适用于
WriteInt64(IntPtr, Int64)
将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory.
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
非托管内存中要写入的地址。The address in unmanaged memory to write to.
- val
- Int64
要写入的值。The value to write.
- 属性
例外
ptr 不是识别的格式。ptr is not a recognized format.
- 或 --or-
ptr 为 null。ptr is null.
- 或 --or-
ptr 无效。ptr is invalid.
示例
下面的示例演示如何使用和方法读取和写入非托管数组 ReadInt64 WriteInt64 。The following example demonstrates how to read and write to an unmanaged array using the ReadInt64 and WriteInt64 methods.
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 实现与非托管64位已签名数组的直接交互,消除在 Marshal.Copy 设置其元素值之前使用) 将整个非托管数组复制 (的代价。WriteInt64 enables direct interaction with an unmanaged 64-bit signed array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before setting its element values.
支持写入未对齐的内存位置。Writing to unaligned memory locations is supported.
另请参阅
适用于
WriteInt64(IntPtr, Int32, Int64)
按指定偏移量将 64 位带符号整数值写入非托管内存。Writes a 64-bit signed integer value to unmanaged memory at a specified offset.
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
非托管内存中要写入的基址。The base address in unmanaged memory to write.
- ofs
- Int32
额外的字节偏移量,在写入前添加到 ptr 参数中。An additional byte offset, which is added to the ptr parameter before writing.
- val
- Int64
要写入的值。The value to write.
- 属性
例外
基址 (ptr) 加上偏移字节 (ofs) 可产生空或无效地址。Base address (ptr) plus offset byte (ofs) produces a null or invalid address.
示例
下面的示例演示如何使用和方法读取和写入非托管数组 ReadInt64 WriteInt64 。The following example demonstrates how to read and write to an unmanaged array using the ReadInt64 and WriteInt64 methods.
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 实现与非托管64位已签名数组的直接交互,消除在 Marshal.Copy 设置其元素值之前使用) 将整个非托管数组复制 (的代价。WriteInt64 enables direct interaction with an unmanaged 64-bit signed array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before setting its element values.
支持写入未对齐的内存位置。Writing to unaligned memory locations is supported.