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 local clone.

std.experimental.allocator.common

Utility and ancillary artifacts of std.experimental.allocator. This module shouldn't be used directly; its functionality will be migrated into more appropriate parts of std.
Authors:
Andrei Alexandrescu, Timon Gehr (Ternary)
struct Ternary;
Ternary type with three thruth values.
enum Ternary no;
enum Ternary yes;
enum Ternary unknown;
In addition to false and true, Ternary offers unknown.
this(bool b);
void opAssign(bool b);
Construct and assign from a bool, receiving no for false and yes for true.
this(const Ternary b);
Construct a ternary value from another ternary value
Ternary opUnary(string s)() if (s == "~");
Ternary opBinary(string s)(Ternary rhs) if (s == "|");
Ternary opBinary(string s)(Ternary rhs) if (s == "&");
Ternary opBinary(string s)(Ternary rhs) if (s == "^");
Truth table for logical operations
a b ˜a a | b a & b a ^ b
no no yes no no no
no yes yes no yes
no unknown unknown no unknown
yes no no yes no yes
yes yes yes yes no
yes unknown yes unknown unknown
unknown no unknown unknown no unknown
unknown yes yes unknown unknown
unknown unknown unknown unknown unknown
template stateSize(T)
Returns the size in bytes of the state that needs to be allocated to hold an object of type T. stateSize!T is zero for structs that are not nested and have no nonstatic member variables.
enum ulong chooseAtRuntime;
chooseAtRuntime is a compile-time constant of type size_t that several parameterized structures in this module recognize to mean deferral to runtime of the exact value. For example, BitmappedBlock!(Allocator, 4096) (described in detail below) defines a block allocator with block size of 4096 bytes, whereas BitmappedBlock!(Allocator, chooseAtRuntime) defines a block allocator that has a field storing the block size, initialized by the user.
enum ulong unbounded;
unbounded is a compile-time constant of type size_t that several parameterized structures in this module recognize to mean "infinite" bounds for the parameter. For example, Freelist (described in detail below) accepts a maxNodes parameter limiting the number of freelist items. If unbounded is passed for maxNodes, then there is no limit and no checking for the number of nodes.
enum uint platformAlignment;
The alignment that is guaranteed to accommodate any D object allocation on the current platform.
size_t goodAllocSize(A)(auto ref A a, size_t n);
The default good size allocation is deduced as n rounded up to the allocator's alignment.
package size_t roundUpToMultipleOf(size_t s, uint base);
Returns s rounded up to a multiple of base.
package size_t roundUpToAlignment(size_t n, uint alignment);
Returns n rounded up to a multiple of alignment, which must be a power of 2.
package size_t roundDownToAlignment(size_t n, uint alignment);
Returns n rounded down to a multiple of alignment, which must be a power of 2.
package void[] roundUpToAlignment(void[] b, uint a);
Advances the beginning of b to start at alignment a. The resulting buffer may therefore be shorter. Returns the adjusted buffer, or null if obtaining a non-empty buffer is impossible.
package size_t divideRoundUp(size_t a, size_t b);
Like a / b but rounds the result up, not down.
package void[] roundStartToMultipleOf(void[] s, uint base);
Returns s rounded up to a multiple of base.
package size_t roundUpToPowerOf2(size_t s);
Returns s rounded up to the nearest power of 2.
package uint trailingZeros(ulong x);
Returns the number of trailing zeros of x.
package bool alignedAt(void* ptr, uint alignment);
Returns true if ptr is aligned at alignment.
package uint effectiveAlignment(void* ptr);
Returns the effective alignment of ptr, i.e. the largest power of two that is a divisor of ptr.
package void* alignDownTo(void* ptr, uint alignment);
Aligns a pointer down to a specified alignment. The resulting pointer is less than or equal to the given pointer.
package void* alignUpTo(void* ptr, uint alignment);
Aligns a pointer up to a specified alignment. The resulting pointer is greater than or equal to the given pointer.
package @nogc bool isPowerOf2(uint x);
Returns true if x is a nonzero power of two.
bool reallocate(Allocator)(ref Allocator a, ref void[] b, size_t s);
The default reallocate function first attempts to use expand. If Allocator.expand is not defined or returns false, reallocate allocates a new block of memory of appropriate size and copies data from the old block to the new block. Finally, if Allocator defines deallocate, reallocate uses it to free the old memory block.
reallocate does not attempt to use Allocator.reallocate even if defined. This is deliberate so allocators may use it internally within their own implementation of reallocate.
bool alignedReallocate(Allocator)(ref Allocator alloc, ref void[] b, size_t s, uint a);
The default alignedReallocate function first attempts to use expand. If Allocator.expand is not defined or returns false, alignedReallocate allocates a new block of memory of appropriate size and copies data from the old block to the new block. Finally, if Allocator defines deallocate, alignedReallocate uses it to free the old memory block.
alignedReallocate does not attempt to use Allocator.reallocate even if defined. This is deliberate so allocators may use it internally within their own implementation of reallocate.
string forwardToMember(string member, string[] funs...);
Forwards each of the methods in funs (if defined) to member.