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.

core.internal.array.utils

This module contains utility functions to help the implementation of the runtime hook
License:
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.
Parameters:
F Function that does not take any parameters
Returns:
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
Parameters:
T Type to check
Returns:
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).
Parameters:
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.
Parameters:
size_t arrSize size of the allocated array in bytes
Returns:
BlkInfo with allocation metadata
pure nothrow void* __arrayStart()(return scope BlkInfo info);
Get the start of the array for the given block.
Parameters:
BlkInfo info array metadata
Returns:
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.