原文地址:https://msdn.microsoft.com/zh-cn/library/ms146631.aspx
- using System;
- using System.Runtime.InteropServices;
-
- class Example
- {
-
- static void Main()
- {
- // Create a managed array.
- byte[] managedArray = { 1, 2, 3, 4 };
-
- // Initialize unmanaged memory to hold the array.
- int size = Marshal.SizeOf(managedArray[0]) * managedArray.Length;
-
- IntPtr pnt = Marshal.AllocHGlobal(size);
-
- try
- {
- // Copy the array to unmanaged memory.
- Marshal.Copy(managedArray, 0, pnt, managedArray.Length);
-
- // Copy the unmanaged array back to another managed array.
-
- byte[] managedArray2 = new byte[managedArray.Length];
-
- Marshal.Copy(pnt, managedArray2, 0, managedArray.Length);
-
- Console.WriteLine("The array was copied to unmanaged memory and back.");
-
- }
- finally
- {
- // Free the unmanaged memory.
- Marshal.FreeHGlobal(pnt);
- }
-
-
-
- }
-
- }

![[手游] 三网H5小游戏【少年仙路】WIN系服务端+Linux手工服务端+详细搭建教程](https://cdn.jxasp.com:9143/image/20260615/136BC33AA47EB0D84E878835A8B38FDB.png)

















