Allocate and free memory : Memory « Windows « C# / CSharp Tutorial






using System;
using System.Runtime.InteropServices;

class MainClass
{
  static void Main(string[] args)
  {
    UsePointers();
  }
  static unsafe public void UsePointers()
  {
    char * pMyArray = (char*)Marshal.AllocCoTaskMem(6);

    while (*pMyArray != '\0')
    {
      Console.WriteLine(*pMyArray);
      pMyArray++;
    }

    Marshal.FreeCoTaskMem((IntPtr)pMyArray);
  }
}








29.13.Memory
29.13.1.Allocate memory with System.Runtime.MemoryFailPoint
29.13.2.Allocate and free memory
29.13.3.Demonstrate stackalloc
29.13.4.Free Memory
29.13.5.Free memory: Marshal.FreeHGlobal
29.13.6.Create Heap and destroy Heap