Материал из .Net Framework эксперт
Fixing Managed Data in Memory
using System;
public class MyClass
{
public unsafe static void Main()
{
int ArrayIndex;
int [] IntegerArray;
IntegerArray = new int [5];
fixed(int * IntegerPointer = IntegerArray)
{
for(ArrayIndex = 0; ArrayIndex < 5; ArrayIndex++)
IntegerPointer[ArrayIndex] = ArrayIndex;
}
for(ArrayIndex = 0; ArrayIndex < 5; ArrayIndex++)
Console.WriteLine(IntegerArray[ArrayIndex]);
}
}
IntPtr.Zero
using System;
using System.Runtime.InteropServices;
public class MainClass
{
[STAThread]
static void Main(string[] args)
{
IntPtr ptr = IntPtr.Zero;
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)));
Marshal.FreeHGlobal(ptr);
}
}