View source code
Display the source code in std/experimental/allocator/building_blocks/affix_allocator.d from which this page was generated on github.
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.

Struct std.experimental.allocator.building_blocks.affix_allocator.AffixAllocator

Allocator that adds some extra data before (of type Prefix) and/or after (of type Suffix) any allocation made with its parent allocator. This is useful for uses where additional allocation-related information is needed, such as mutexes, reference counts, or walls for debugging memory corruption errors.

struct AffixAllocator(Allocator, Prefix, Suffix) ;

If Prefix is not void, Allocator must guarantee an alignment at least as large as Prefix.alignof.

Suffixes are slower to get at because of alignment rounding, so prefixes should be preferred. However, small prefixes blunt the alignment so if a large alignment with a small affix is needed, suffixes should be chosen.

The following methods are defined if Allocator defines them, and forward to it: deallocateAll, empty, owns.

Fields

NameTypeDescription
_parent AllocatorIf the parent allocator Allocator is stateful, an instance of it is stored as a member. Otherwise, AffixAllocator uses Allocator.instance. In either case, the name _parent is uniformly used for accessing the parent allocator.
instance AffixAllocatorThe instance singleton is defined if and only if the parent allocator has no state and defines its own it object.

Methods

NameDescription
allocate () Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
deallocate (b) Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
deallocateAll () Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
empty () Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
expand (b, delta) Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
goodAllocSize () Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
owns () Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
parent () If the parent allocator Allocator is stateful, an instance of it is stored as a member. Otherwise, AffixAllocator uses Allocator.instance. In either case, the name _parent is uniformly used for accessing the parent allocator.
prefix (b) Affix access functions offering references to the affixes of a block b previously allocated with this allocator. b may not be null. They are defined if and only if the corresponding affix is not void.
reallocate (b, s) Standard allocator methods. Each is defined if and only if the parent allocator defines the homonym method (except for goodAllocSize, which may use the global default). Also, the methods will be shared if the parent allocator defines them as such.
suffix (b) Affix access functions offering references to the affixes of a block b previously allocated with this allocator. b may not be null. They are defined if and only if the corresponding affix is not void.

Example

import std.experimental.allocator.mallocator : Mallocator;
// One word before and after each allocation.
alias A = AffixAllocator!(Mallocator, size_t, size_t);
auto b = A.instance.allocate(11);
A.instance.prefix(b) = 0xCAFE_BABE;
A.instance.suffix(b) = 0xDEAD_BEEF;
assert(A.instance.prefix(b) == 0xCAFE_BABE
    && A.instance.suffix(b) == 0xDEAD_BEEF);

Authors

License