This module contains all functions related to an object's lifetime: allocation, resizing, deallocation, and finalization.
This is called for a delete statement where the value being deleted is a pointer to a struct with a destructor but doesn't have an overloaded delete operator.
Set the allocated length of the array block. This is called any time 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.
get the allocation size of the array for the given block (without padding or type info)
get the start of the array for the given block
get the padding required to allocate size bytes. Note that the padding is NOT included in the passed in size. Therefore, do NOT call this function with the size of an allocated block.
allocate an array memory block by applying the proper padding and assigning block attributes if not inherited from the existing block
cache for the lookup of the block info
Get the cached block info of an interior pointer. Returns null if the interior pointer's block is not cached.
Shrink the "allocated" length of an array to be the exact size of the array. It doesn't matter what the current allocated length of the array is, the user is telling the runtime that he knows what he is doing.
set the array capacity. If the array capacity isn't currently large enough to hold the requested capacity (in number of elements), then the array is resized/reallocated to the appropriate size. Pass in a requested capacity of 0 to get the current capacity. Returns the number of elements that can actually be stored once the resizing is done.
Allocate a new uninitialized array of length elements. ti is the type of the resulting array, or pointer to element.
Allocate a new array of length elements. ti is the type of the resulting array, or pointer to element. (For when the array is initialized to 0)
For when the array has a non-zero initializer.
Allocate an uninitialized non-array item. This is an optimization to avoid things needed for arrays like the _arrayPad(size).
Same as above, zero initializes the item.
Same as above, for item with non-zero initializer.
Resize dynamic arrays with 0 initializers.
Resize arrays for non-zero initializers. p pointer to array lvalue to be updated newlength new .length property of array sizeelem size of each element of array initsize size of initializer ... initializer
Append y[] to array x[]
Extend an array by n elements. Caller must initialize those elements.
Append dchar to char[]
Append dchar to wchar[]
Allocate the array, rely on the caller to do the initialization of the array.
© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/rt_lifetime.html