bit::memory
|
This concept defines the required interface and semantics expected of an allocator. More...
Modules | |
ExtendedAllocator | |
This concept defines the required interface and semantics expected of an extended allocator. | |
Classes | |
class | bit::memory::aligned_allocator |
This stateless allocator performs all of its allocation calls using aligned memory invocations. More... | |
class | bit::memory::allocator_reference |
A non-owning allocator type that type-erases an underlying allocator. More... | |
class | bit::memory::fallback_allocator< AllocatorStorages > |
This allocator acts as an aggregate that can fall back to other allocators on failure. More... | |
class | bit::memory::malloc_allocator |
This stateless allocator performs all of its allocation calls using raw calls to 'malloc', and frees memory with 'free'. More... | |
class | bit::memory::new_allocator |
This stateless allocator performs all of its allocation calls using raw calls to 'new', and frees memory with 'delete'. More... | |
class | bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable > |
This allocator manages policy-based memory allocation strategies using policy-based-design. More... | |
This concept defines the required interface and semantics expected of an allocator.
The bit::memory
Allocator concept varies from the C++ standard's definition of the concept. One major difference is that an Allocator is not templated on the type. Instead, an allocator simply must satisfy the requirements of minimally supplying a non-throwing try_allocate
and deallocate
function with a specific signature.
The rationale for this follows HP and SGI's rationale for removing the template type; it's easier to be dealing with raw bytes from a system, and giving it the single responsibility of allocating the data.
For type A
to be Allocator
, it must satisfy the following:
Provided
A
- an Allocator typea
- an instance of type A
s
- the size of an allocationn
- the alignment of the allocationp
- a void pointerthe following expressions must be well-formed with the expected side-effects:
a
tries to allocate at least s
bytes aligned to the boundary n
. This function returns nullptr
on failure to allocate, otherwise returns a pointer to data at least s
bytes large, aligned to a n
byte boundary.
The expression
must be non-throwing, otherwise it is undefined behaviour.
Deallocates the memory pointer to by v
with the allocation size s
. The size must match the original size requested by a.try_allocate
, otherwise it is undefined behaviour. Any use of v
after a call to a.deallocate
is undefined behaviour.
Optionally
a
allocates at least s
bytes aligned to the boundary n
.
The behaviour of this function is implementation-defined on failure (may throw, may invoke out-of-memory handler, etc).
The default for this is to invoke out-of-memory handler on nullptr
if an implementation is not provided
a
deallocates all entries inside of the allocator. Any existing pointers are now invalidated
Default asserts.
a
returns an allocator_info object describing the allocator
The default value is implementation-defined, but should somehow identify the allocator
a
checks whether it owns the pointer p
, returning the result.
Returns the maximum size the allocator can support
Default is std::numeric_limits<std::size_t>::max()
Returns the minimum size the allocator can support
Default is 1
Determines the default-alignment of allocations from the given allocator. This allows certain optimizations to be made by making assumptions about the allocated results (such as avoiding the need of storing padding-offset for alignment, if it's always guaranteed to align to the correct boundary).
Default is 1
.
Determines the maximum-alignment for allocations from the given allocator. Any specified alignment argument that exceeds this value results in undefined behaviour.
Default is alignof(std::max_align_t)