Demonstrate stackalloc : Memory « Windows « C# / CSharp Tutorial






using System; 
 
class MainClass { 
  unsafe public static void Main() { 
    int* ptrs = stackalloc int[3]; 
 
    ptrs[0] = 1; 
    ptrs[1] = 2; 
    ptrs[2] = 3; 
 
    for(int i=0; i < 3; i++) 
      Console.WriteLine(ptrs[i]); 
  } 
}
1
2
3








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