Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


This module contains utility functions to help the implementation of the runtime hook
Distributed under the Boost Software License 1.0. (See accompanying file LICENSE)
enum auto isNoThrow(alias F);
Check if the function F is calleable in a nothrow scope.
F Function that does not take any parameters
if the function is callable in a nothrow scope.
template isPostblitNoThrow(T)
Check if the type T's postblit is called in nothrow, if it exist
T Type to check
if the postblit is callable in a nothrow scope, if it exist. if it does not exist, return true.
pure nothrow void __arrayClearPad()(ref BlkInfo info, size_t arrSize, size_t padSize);
Clear padding that might not be zeroed by the GC (it assumes it is within the requested size from the start, but it is actually at the end of the allocated block).
BlkInfo info array allocation data
size_t arrSize size of the array in bytes
size_t padSize size of the padding in bytes
@trusted BlkInfo __arrayAlloc(T)(size_t arrSize);
Allocate an array memory block by applying the proper padding and assigning block attributes if not inherited from the existing block.
size_t arrSize size of the allocated array in bytes
BlkInfo with allocation metadata
pure nothrow void* __arrayStart()(return scope BlkInfo info);
Get the start of the array for the given block.
BlkInfo info array metadata
pointer to the start of the array
bool __setArrayAllocLength(T)(ref BlkInfo info, size_t newLength, bool isShared, size_t oldLength = ~0);
Set the allocated length of the array block. This is called when an array is appended to or its length is set.
The allocated block looks like this for blocks < PAGESIZE: |elem0|elem1|elem2|...|elemN-1|emptyspace|N*elemsize|
The size of the allocated length at the end depends on the block size: a block of 16 to 256 bytes has an 8-bit length. a block with 512 to pagesize/2 bytes has a 16-bit length.
For blocks >= pagesize, the length is a size_t and is at the beginning of the block. The reason we have to do this is because the block can extend into more pages, so we cannot trust the block length if it sits at the end of the block, because it might have just been extended. If we can prove in the future that the block is unshared, we may be able to change this, but I'm not sure it's important.
In order to do put the length at the front, we have to provide 16 bytes buffer space in case the block has to be aligned properly. In x86, certain SSE instructions will only work if the data is 16-byte aligned. In addition, we need the sentinel byte to prevent accidental pointers to the next block. Because of the extra overhead, we only do this for page size and above, where the overhead is minimal compared to the block size.
So for those blocks, it looks like: `|N*elemsize|padding|elem0|elem1|...|elemN-1|emptyspace|sentinelbyte|``
where elem0 starts 16 bytes after the first byte.