添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
谦虚好学的紫菜  ·  sqlalchemy all vs ...·  9 月前    · 
愉快的铁链  ·  C# ...·  1 年前    · 
很酷的钢笔  ·  cluster computing - ...·  1 年前    · 
public:
 static void WriteIntPtr(IntPtr ptr, IntPtr val);
[System.Security.SecurityCritical]
public static void WriteIntPtr (IntPtr ptr, IntPtr val);
public static void WriteIntPtr (IntPtr ptr, IntPtr val);
[<System.Security.SecurityCritical>]
static member WriteIntPtr : nativeint * nativeint -> unit
static member WriteIntPtr : nativeint * nativeint -> unit
Public Shared Sub WriteIntPtr (ptr As IntPtr, val As IntPtr)
// Allocate unmanaged memory. int elementSize = Marshal.SizeOf(typeof(IntPtr)); IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize); // Set the 10 elements of the C-style unmanagedArray for (int i = 0; i < 10; i++) Marshal.WriteIntPtr(unmanagedArray, i * elementSize, ((IntPtr)(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.ReadIntPtr(unmanagedArray, i * elementSize)); Marshal.FreeHGlobal(unmanagedArray); Console.WriteLine("Done. Press Enter to continue."); Console.ReadLine(); Sub ReadWriteIntPtr() ' Allocate unmanaged memory. Dim elementSize As Integer = Marshal.SizeOf(GetType(IntPtr)) 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.WriteIntPtr(unmanagedArray, i * elementSize, CType(i + 1, IntPtr)) 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.ReadIntPtr(unmanagedArray, i * elementSize)) Next i Marshal.FreeHGlobal(unmanagedArray) Console.WriteLine("Done. Press Enter to continue.") Console.ReadLine() End Sub

WriteIntPtr 允許與 Unmanaged C 樣式 IntPtr 陣列直接互動,不需要先將整個 Unmanaged 陣列複製 (使用 Marshal.Copy ) 個別 Managed 陣列,再設定其元素值。

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

public:
 static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val);
[System.Security.SecurityCritical]
public static void WriteIntPtr (IntPtr ptr, int ofs, IntPtr val);
public static void WriteIntPtr (IntPtr ptr, int ofs, IntPtr val);
[<System.Security.SecurityCritical>]
static member WriteIntPtr : nativeint * int * nativeint -> unit
static member WriteIntPtr : nativeint * int * nativeint -> unit
Public Shared Sub WriteIntPtr (ptr As IntPtr, ofs As Integer, val As IntPtr)
// Allocate unmanaged memory. int elementSize = Marshal.SizeOf(typeof(IntPtr)); IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize); // Set the 10 elements of the C-style unmanagedArray for (int i = 0; i < 10; i++) Marshal.WriteIntPtr(unmanagedArray, i * elementSize, ((IntPtr)(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.ReadIntPtr(unmanagedArray, i * elementSize)); Marshal.FreeHGlobal(unmanagedArray); Console.WriteLine("Done. Press Enter to continue."); Console.ReadLine(); Sub ReadWriteIntPtr() ' Allocate unmanaged memory. Dim elementSize As Integer = Marshal.SizeOf(GetType(IntPtr)) 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.WriteIntPtr(unmanagedArray, i * elementSize, CType(i + 1, IntPtr)) 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.ReadIntPtr(unmanagedArray, i * elementSize)) Next i Marshal.FreeHGlobal(unmanagedArray) Console.WriteLine("Done. Press Enter to continue.") Console.ReadLine() End Sub

這個方法會在 32 位系統上寫入 32 位整數,並在 64 位系統上寫入 64 位整數。

WriteIntPtr 允許與 Unmanaged C 樣式 IntPtr 陣列直接互動,不需要先將整個 Unmanaged 陣列複製 (使用 Marshal.Copy ) 個別 Managed 陣列,再設定其元素值。

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

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

WriteIntPtr 可讓您與 Unmanaged C 樣式的位元組陣列直接互動,避免在設定其元素值之前,先將 Marshal.Copy 整個 Unmanaged 陣列複製 () (。

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