Allocate memory with System.Runtime.MemoryFailPoint : Memory « Windows « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;

public class MainClass
{

    public static void Main()
    {
        using (System.Runtime.MemoryFailPoint gate = new System.Runtime.MemoryFailPoint(100))
        {
            // Some operation that actually uses the 100MB of memory
            Console.WriteLine("Success for 100MB fail-point");
        }

        using (System.Runtime.MemoryFailPoint gate = new System.Runtime.MemoryFailPoint(1024*100))
        {
            // Some operation that actually uses the 100GB of memory
            Console.WriteLine("Success for 100GB fail-point");
        }
    }
}








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