rt.lifetime - D Programming Language
Description: D Programming Language
Keywords: D programming language

Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Calendar
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
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_t `sz`);
Object `_d_newclass`(const ClassInfo `ci`);
void `_d_delinterface`(void** `p`);
void `_d_delclass`(Object* `p`);
void `_d_delstruct`(void** `p`, TypeInfo_Struct `inf`);
  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 BlkInfo `info`, size_t `newlength`, bool `isshared`, const TypeInfo `tinext`, size_t `oldlength` = ~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 BlkInfo `info`, const TypeInfo `tinext`);
  get the allocation size of the array for the given block (without padding or type info)
pure nothrow void* `__arrayStart`(return BlkInfo `info`);
  get the start of the array for the given block
pure nothrow @trusted size_t `__arrayPad`(size_t `size`, const TypeInfo `tinext`);
  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_t `arrsize`, const TypeInfo `ti`, const TypeInfo `tinext`);
  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 TypeInfo `ti`, 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 TypeInfo `ti`, size_t `newcapacity`, 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`(const TypeInfo `ti`, size_t `length`);
  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 TypeInfo `ti`, size_t `length`);
  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 TypeInfo `ti`, size_t `length`);
  For when the array has a non-zero initializer.
void[] `_d_newarrayOpT`(alias op)(const TypeInfo `ti`, size_t[] `dims`);
void[] `_d_newarraymTX`(const TypeInfo `ti`, size_t[] `dims`);
void[] `_d_newarraymiTX`(const TypeInfo `ti`, 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_Struct `ti`);
void `_d_delmemory`(void** `p`);
void `_d_callinterfacefinalizer`(void* `p`);
void `_d_callfinalizer`(void* `p`);
void `rt_setCollectHandler`(CollectHandler `h`);
CollectHandler `rt_getCollectHandler`();
nothrow int `rt_hasFinalizerInSegment`(void* `p`, size_t `size`, uint `attr`, in void[] `segment`);
nothrow void `rt_finalize2`(void* `p`, bool `det` = true, bool `resetMemory` = true);
void[] `_d_arraysetlengthT`(const TypeInfo `ti`, size_t `newlength`, void[]* `p`);
  Resize dynamic arrays with 0 initializers.
void[] `_d_arraysetlengthiT`(const TypeInfo `ti`, size_t `newlength`, 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 TypeInfo `ti`, ref byte[] `x`, byte[] `y`);
  Append y[] to array x[]
size_t `newCapacity`(size_t `newlength`, size_t `size`);
byte[] `_d_arrayappendcTX`(const TypeInfo `ti`, ref byte[] `px`, size_t `n`);
  Extend an array by n elements. Caller must initialize those elements.
void[] `_d_arrayappendcd`(ref byte[] `x`, dchar `c`);
  Append dchar to char[]
void[] `_d_arrayappendwd`(ref byte[] `x`, dchar `c`);
  Append dchar to wchar[]
byte[] `_d_arraycatT`(const TypeInfo `ti`, byte[] `x`, byte[] `y`);
void[] `_d_arraycatnTX`(const TypeInfo `ti`, byte[][] `arrs`);
void* `_d_arrayliteralTX`(const TypeInfo `ti`, size_t `length`);
  Allocate the array, rely on the caller to do the initialization of the array.

Copyright © 1999-2021 by the D Language Foundation | Page generated by Ddoc on Tue Jul 20 05:58:35 2021