dstats.alloc

Stuff having to do with memory management. Mostly a copy of RegionAllocator for now until it gets into Phobos, as well as some RegionAllocator-specific data structures.

Public Imports

scid.internal.regionallocator
public import scid.internal.regionallocator;
Undocumented in source.

Members

Classes

RegionAllocatorException
class RegionAllocatorException

The exception that is thrown on invalid use of $(RegionAllocator) and RegionAllocatorStack. This exception is not thrown on out of memory. An OutOfMemoryError is thrown instead.

Enums

GCScan
enum GCScan

This flag determines whether a given RegionAllocatorStack is scanned for pointers by the garbage collector (GC). If yes, the entire stack is scanned, not just the part currently in use, since there is currently no efficient way to modify the bounds of a GC region. The stack is scanned conservatively, meaning that any bit pattern that would point to GC-allocated memory if interpreted as a pointer is considered to be a pointer. This can result in GC-allocated memory being retained when it should be freed. Due to these caveats, it is recommended that any stack scanned by the GC be small and/or short-lived.

Functions

appendDelOld
void appendDelOld(T[] to, U from)

Appends to an array, deleting the old array if it has to be realloced.

newRegionAllocator
RegionAllocator newRegionAllocator()

Returns a new RegionAllocator that uses the default thread-local RegionAllocatorStack instance.

scanThreadLocalStack
bool scanThreadLocalStack()
bool scanThreadLocalStack(bool shouldScan)

These properties determine whether the default thread-local RegionAllocatorStack instance is scanned by the garbage collector. The default is no. In most cases, scanning a stack this long-lived is not recommended, as it will cause too many false pointers. (See std.regionallocator.GCScan for details.)

threadLocalSegmentSize
size_t threadLocalSegmentSize()
size_t threadLocalSegmentSize(size_t newSize)

These properties get and set the segment size of the default thread-local RegionAllocatorStack instance. The default size is 4 megabytes. The setter is only effective before the global function newRegionAllocator has been called for the first time in the current thread. Attempts to set this property after the first call to this function from the current thread throw a RegionAllocatorException.

Structs

AVLNodeBitwise
struct AVLNodeBitwise(T)
Undocumented in source.
AVLNodeRealHeight
struct AVLNodeRealHeight(T)
Undocumented in source.
HashRange
struct HashRange(K, S, bool vals = false)

Forward range struct for iterating over the keys or values of a * StackHash or StackSet. The lifetime of this object must not exceed that * of the underlying StackHash or StackSet.

RegionAllocator
struct RegionAllocator

This struct provides an interface to the RegionAllocator functionality and enforces scoped deletion. A new instance using the thread-local RegionAllocatorStack instance is created using the global newRegionAllocator function. A new instance using an explicitly created RegionAllocatorStack is created using RegionAllocatorStack.newRegionAllocator.

RegionAllocatorStack
struct RegionAllocatorStack

This object represents a segmented stack. Memory can be allocated from this stack using a std.regionallocator RegionAllocator. object. Multiple RegionAllocator objects may be created per RegionAllocatorStack but each RegionAllocator uses a single RegionAllocatorStack.

SimpleStack
struct SimpleStack(T)
Undocumented in source.
StackHash
struct StackHash(K, V)

A hash table that allocates its memory on RegionAllocator. Good for building a temporary hash tables that will not escape the current scope.

StackSet
struct StackSet(K)

A hash set that allocates its memory on RegionAllocator. Good for building a temporary set that will not escape the current scope.

StackTree
struct StackTree(T, alias key = "a", alias compFun = "a < b")

An AVL tree implementation on top of RegionAllocator. If elements are removed, they are stored on an internal free list and recycled when new elements are added to the tree.

StackTreeAA
struct StackTreeAA(K, V)

An associative array implementation based on StackTree. Lookups and insertions are O(log N). This is significantly slower in both theory and practice than StackHash, but you may want to use it if:

TreeAaIter
struct TreeAaIter(T, alias mapFun)

Struct that iterates over keys or values of a StackTreeAA.

Variables

defaultSegmentSize
enum size_t defaultSegmentSize;
Undocumented in source.

Meta

Authors

David Simcha