Functions for heap manipulation
Returns default heap of the calling process.
This struct encapsulates heap manipulation functionality.
Mostly it is a convinient wrapper for WinAPI heap functions.
Construct a Heap from a heapHandle.
Returns whether this is associated with a heap handle. It is asserted that no member functions are called for an unassociated Heap struct.
assert(processHeap.associated); assert(!Heap.init.associated); auto h = Heap.init.handle; // assert violation
Gets the handle of the associated heap.
Allocates a block of memory.
Also see HeapAlloc.
Reallocates a block of memory (i.e. memory content is preserved).
If array is null, works as alloc.
See also
HeapReAlloc.
Reallocates a block of memory without preserving its content.
If array is null, works as alloc. Destructive reallocation is often needed when dealing with functions requiring unpredictable buffer size. See example.
HMODULE[] enumProcessModulesHelper(HANDLE hProcess) { HMODULE[] buff; DWORD needed = 0; do { processHeap.destructiveRealloc!HMODULE(buff, max(needed + 0x100, buff.length * 2)); scope(failure) processHeap.free(buff.ptr); enforce(EnumProcessModules(hProcess, buff.ptr, buff.length * HMODULE.sizeof, &needed)); assert(needed % HMODULE.sizeof == 0); needed /= HMODULE.sizeof; } while(needed > buff.length); return buff[0 .. needed]; }
Frees a block of memory.
See also HeapFree.