Unstandard

Convenient wrapper for WinAPI heap functions.

License
Boost License 1.0.
Authors
Denis Shelomovskij

@property @trusted Heap  processHeap();

Returns default heap of the calling process.


struct  Heap;

This struct encapsulates heap manipulation functionality.

This struct is neither default constructable nor copyable. Pass it by ref to functions or use std.typecons.RefCounted.


enum  CreateOptions: uint;

Heap construction options.


 no

No flags.


Add HEAP_CREATE_ENABLE_EXECUTE flag.


Add HEAP_GENERATE_EXCEPTIONS flag.


Add HEAP_NO_SERIALIZE flag.


enum  Flags: uint;

General heap usage flags.


 no

No flags.


Add HEAP_GENERATE_EXCEPTIONS flag.


Add HEAP_NO_SERIALIZE flag.


@trusted this(CreateOptions options, in size_t initialSize = 0, in size_t maximumSize = 0);

Construct a new Heap.

Wrapper for HeapCreate.

Throws
WinAPIException if heap creation failed.

pure nothrow @safe this(HANDLE heapHandle, in bool own = true);

Construct a Heap from a heapHandle.

If own is true destroys the heapHandle on destruction using HeapDestroy.


const pure nothrow @property @safe bool  associated();

Returns whether this is associated with a heap handle. It is asserted that no member functions are called for an unassociated Heap struct.

Examples
assert(processHeap.associated);
assert(!Heap.init.associated);
auto h = Heap.init.handle; // assertion failure

pure nothrow @property @safe HANDLE  handle();

Gets the handle of the associated heap.


const pure nothrow @property @safe bool  ownHandle();

Returns whether handle of the associated heap will be destroyed on destruction.


nothrow @trusted void*  alloc(in size_t bytes, in bool zeroMemory = false, Flags flags = Flags.no);

Allocates a block of memory.

Wrapper for HeapAlloc.


nothrow @system void*  reAlloc(void* ptr, in size_t bytes, in bool zeroMemory = false, in bool inPlaceOnly = false, Flags flags = Flags.no);

Reallocates a block of memory (i.e. memory content is preserved).

Wrapper for HeapReAlloc.


@system void  free(void* p, in Flags flags = Flags.no);

Frees a block of memory.

Wrapper for HeapFree. Also fixes HeapFree bug, see "Community Additions" section of function page.

Throws
WinAPIException if memory freeing failed.

@system size_t  size(void* p, in Flags flags = Flags.no);

Retrieves the size of an allocated from this heap memory block.

Wrapper for HeapSize.

Throws
WinAPIException if getting size failed.

struct  HeapAllocator;

An unaligned thread local allocator interface implementation for Heap.

Can be constructed using the same arguments as Heap.

Underlying Heap can be accessed via heap property.

See also unstd.memory.allocation.isUnalignedAllocator.