Create Heap and destroy Heap : Memory « Windows « C# / CSharp Tutorial






using System;
using System.Runtime.InteropServices;

public sealed class MainClass
{
    [DllImport("kernel32.dll")]
    static extern IntPtr HeapCreate(uint flOptions, UIntPtr dwInitialSize,UIntPtr dwMaximumSize);

    [DllImport("kernel32.dll")]
    static extern bool HeapDestroy(IntPtr hHeap);

    public static void Main() {
        IntPtr theHeap = HeapCreate( 0, (UIntPtr) 4096, UIntPtr.Zero );
        HeapDestroy( theHeap );
        theHeap = IntPtr.Zero;
    }
}








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