HeapCreate (kernel32)
Last changed: shtolliver-47.227.243.115

.
Summary

Creates a private heap object that can be used by the calling process. The function reserves space in the virtual

address space of the process and allocates physical storage for a specified initial portion of this block.

C# Signature:

    /// <summary>
    /// HeapCreate - Creates a private heap object that can be used by the calling process.
    /// The function reserves space in the virtual address space of the process and allocates
    /// physical storage for a specified initial portion of this block.
    /// Ref: https://learn.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapcreate
    /// </summary>
    /// <param name="flOptions"></param>
    /// <param name="dwInitialSize"></param>
    /// <param name="dwMaximumSize"></param>
    /// <returns></returns>
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern IntPtr HeapCreate(UInt32 flOptions, UIntPtr dwInitialSize, UIntPtr dwMaximumSize);

User-Defined Types:

flOptions - https://pinvoke.net/default.aspx/Enums/flOptions.html

Notes:

Conversion of Int/Unit32/long/UIntPtr/IntPtr - much debate, this code could be checked properly.

Tips & Tricks:

Please add some!

Sample Code:

    /// <summary>
    /// HeapCreateMemory  - Creates a private heap object that can be used by the
    ///  calling process. The function reserves space in the virtual address space
    ///  of the process and allocates physical storage for a specified initial portion of this block.
    /// </summary>
    /// <param name="optionType"></param>
    /// <param name="initialbyteSize"></param>
    /// <param name="MaxByteSize"></param>
    /// <returns></returns>
    public static IntPtr HeapCreateMemory(FLOptionType optionType, int initialbyteSize, int MaxByteSize)
    {
      try
      {
    return HeapCreate((UInt32)optionType, (UIntPtr)initialbyteSize, (UIntPtr)MaxByteSize);
      }
      catch (Exception e)
      {
    throw e;
      }
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
HeapCreate on MSDN