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.
rt.lifetime
This module contains all functions related to an object's lifetime:
allocation, resizing, deallocation, and finalization.
License:
Distributed under the
Boost Software License 1.0.
(See accompanying file LICENSE)
Authors:
Walter Bright, Sean Kelly, Steven Schveighoffer
Source rt/lifetime.d
- void*
_d_allocmemory
(size_tsz
); - Object
_d_newclass
(const ClassInfoci
); - void
_d_delinterface
(void**p
); - void
_d_delclass
(Object*p
); - void
_d_delstruct
(void**p
, TypeInfo_Structinf
); - 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.
- pure nothrow bool
__setArrayAllocLength
(ref BlkInfoinfo
, size_tnewlength
, boolisshared
, const TypeInfotinext
, size_toldlength
= ~0); - 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.
- pure nothrow size_t
__arrayAllocLength
(ref BlkInfoinfo
, const TypeInfotinext
); - get the allocation size of the array for the given block (without padding or type info)
- pure nothrow void*
__arrayStart
(return BlkInfoinfo
); - get the start of the array for the given block
- pure nothrow @trusted size_t
__arrayPad
(size_tsize
, const TypeInfotinext
); - 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.
- pure nothrow BlkInfo
__arrayAlloc
(size_tarrsize
, scope const TypeInfoti
, const TypeInfotinext
); - allocate an array memory block by applying the proper padding and assigning block attributes if not inherited from the existing block
- enum int
N_CACHE_BLOCKS
; - cache for the lookup of the block info
- nothrow BlkInfo*
__getBlkInfo
(void*interior
); - Get the cached block info of an interior pointer. Returns null if the interior pointer's block is not cached.
NOTE The base ptr in this struct can be cleared asynchronously by the GC, so any use of the returned BlkInfo should copy it and then check the base ptr of the copy before actually using it.
TODO Change this function so the caller doesn't have to be aware of this issue. Either return by value and expect the caller to always check the base ptr as an indication of whether the struct is valid, or set the BlkInfo as a side-effect and return a bool to indicate success.
- void
_d_arrayshrinkfit
(const TypeInfoti
, void[]arr
); - 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.
- size_t
_d_arraysetcapacity
(const TypeInfoti
, size_tnewcapacity
, void[]*p
); - 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.
- pure nothrow void[]
_d_newarrayU
(scope const TypeInfoti
, size_tlength
); - Allocate a new uninitialized array of length elements. ti is the type of the resulting array, or pointer to element.
- pure nothrow void[]
_d_newarrayT
(const TypeInfoti
, size_tlength
); - 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)
- pure nothrow void[]
_d_newarrayiT
(const TypeInfoti
, size_tlength
); - For when the array has a non-zero initializer.
- void[]
_d_newarrayOpT
(alias op)(const TypeInfoti
, size_t[]dims
); - void[]
_d_newarraymTX
(const TypeInfoti
, size_t[]dims
); - void[]
_d_newarraymiTX
(const TypeInfoti
, size_t[]dims
); - pure nothrow void*
_d_newitemU
(scope const TypeInfo_ti
); - Allocate an uninitialized non-array item. This is an optimization to avoid things needed for arrays like the _arrayPad(size).
- pure nothrow void*
_d_newitemT
(in TypeInfo_ti
); - Same as above, zero initializes the item.
- pure nothrow void*
_d_newitemiT
(in TypeInfo_ti
); - Same as above, for item with non-zero initializer.
- struct
Array
; - void
_d_delarray_t
(void[]*p
, const TypeInfo_Structti
); - void
_d_delmemory
(void**p
); - void
_d_callinterfacefinalizer
(void*p
); - void
_d_callfinalizer
(void*p
); - void
rt_setCollectHandler
(CollectHandlerh
); - CollectHandler
rt_getCollectHandler
(); - nothrow int
rt_hasFinalizerInSegment
(void*p
, size_tsize
, uintattr
, in void[]segment
); - nothrow void
rt_finalize2
(void*p
, booldet
= true, boolresetMemory
= true); - void[]
_d_arraysetlengthT
(const TypeInfoti
, size_tnewlength
, void[]*p
); - Resize dynamic arrays with 0 initializers.
- void[]
_d_arraysetlengthiT
(const TypeInfoti
, size_tnewlength
, void[]*p
); - 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
- void[]
_d_arrayappendT
(const TypeInfoti
, ref byte[]x
, byte[]y
); - Append y[] to array x[]
- size_t
newCapacity
(size_tnewlength
, size_tsize
); - byte[]
_d_arrayappendcTX
(const TypeInfoti
, return ref scope byte[]px
, size_tn
); - Extend an array by n elements. Caller must initialize those elements.
- void[]
_d_arrayappendcd
(ref byte[]x
, dcharc
); - Append dchar to char[]
- void[]
_d_arrayappendwd
(ref byte[]x
, dcharc
); - Append dchar to wchar[]
- byte[]
_d_arraycatT
(const TypeInfoti
, byte[]x
, byte[]y
); - void[]
_d_arraycatnTX
(const TypeInfoti
, scope byte[][]arrs
); - void*
_d_arrayliteralTX
(const TypeInfoti
, size_tlength
); - Allocate the array, rely on the caller to do the initialization of the array.
Copyright © 1999-2022 by the D Language Foundation | Page generated by
Ddoc on (no date time)