bit::memory
|
The allocator_traits class template provides a standardized way to access allocator functionality. More...
#include <allocator_traits.hpp>
Public Types | |
using | pointer = allocator_pointer_t< Allocator > |
using | const_pointer = allocator_const_pointer_t< Allocator > |
using | size_type = allocator_size_type_t< Allocator > |
using | difference_type = allocator_difference_type_t< Allocator > |
template<typename T > | |
using | pointer_rebind = typename detail::allocator_pointer_rebind< Allocator, T >::type |
Rebinds a pointer to the new pointer type. More... | |
using | default_alignment = allocator_default_alignment< Allocator > |
using | max_alignment = allocator_max_alignment< Allocator > |
using | can_truncate_deallocations = allocator_can_truncate_deallocations< Allocator > |
using | knows_ownership = allocator_knows_ownership< Allocator > |
using | uses_pretty_pointers = negation< std::is_same< void *, pointer_rebind< void > >> |
Public Member Functions | |
size_type | recommended_allocation_size (const Allocator &alloc, size_type requested) |
Determines the recommended allocation size of requested bytes from the given allocator. More... | |
Static Public Member Functions | |
static void | deallocate (Allocator &alloc, pointer p, size_type size) |
Deallocates a pointer previously allocated with allocate or try_allocate. More... | |
template<typename U = Allocator, typename = std::enable_if<can_truncate_deallocations::value>> | |
static void | deallocate_all (Allocator &alloc) |
Deallocates all memory from the given allocator. More... | |
template<typename T , typename... Args> | |
static void | construct (Allocator &alloc, void *p, Args &&...args) |
Constructs an instance of T at address p with args . More... | |
template<typename T , typename... Args> | |
static detail::allocator_pointer_rebind< Allocator, T >::type | make (Allocator &alloc, Args &&...args) |
Allocates and constructs a type T with the arguments args . More... | |
template<typename T > | |
static void | destroy (Allocator &alloc, T *p) |
Destroys the instance at p by invoking the destructor. More... | |
template<typename Pointer , typename = std::enable_if_t<is_typed_pointer<Pointer>>> | |
static void | dispose (Allocator &alloc, const Pointer &p) |
Disposes of the given type T . More... | |
template<typename Pointer , typename = std::enable_if_t<is_typed_pointer<Pointer>>> | |
static void | dispose_array (Allocator &alloc, const Pointer &p, size_type n) |
Disposes of the given array of T. More... | |
static bool | owns (const Allocator &alloc, const_pointer p) noexcept |
Checks if the given allocator is known to own the specified pointer p . More... | |
static allocator_info | info (const Allocator &alloc) noexcept |
Gets the name of the specified allocator. More... | |
template<typename T > | |
static std::pointer_traits< pointer >::template rebind< T > | pointer_to (Allocator &alloc, T &x) noexcept |
Converts a reference to an entry into a pointer used by this allocator. More... | |
template<typename Pointer , typename = std::enable_if_t<is_typed_pointer<Pointer>>> | |
static std::pointer_traits< Pointer >::element_type * | to_raw_pointer (Allocator &alloc, const Pointer &p) noexcept |
Converts a pointer from this allocator into a reference. More... | |
static bool | is_unbounded (const Allocator &alloc) noexcept |
Determines if an allocator is unbounded. More... | |
static size_type | max_size (const Allocator &alloc) noexcept |
Gets the maximum size allocateable from this allocator. More... | |
static size_type | min_size (const Allocator &alloc) noexcept |
Gets the minimum size allocateable from this allocator. More... | |
static pointer | try_allocate (Allocator &alloc, size_type size, size_type align) noexcept |
Attempts to allocate memory of at least size bytes, aligned to align boundary. More... | |
static pointer | try_allocate (Allocator &alloc, const_pointer hint, size_type size, size_type align) noexcept |
Attempts to allocate memory of at least size bytes, aligned to align boundary. More... | |
static pointer | allocate (Allocator &alloc, size_type size, size_type align) |
Allocates memory of at least size bytes, aligned to align boundary. More... | |
static pointer | allocate (Allocator &alloc, const_pointer hint, size_type size, size_type align) |
Allocates memory of at least size bytes, aligned to align boundary. More... | |
static bool | expand (Allocator &alloc, pointer p, size_type new_size) |
Expands the memory addres located at p to contain new_size bytes. More... | |
template<typename T > | |
static std::pointer_traits< pointer >::template rebind< T > | make_array (Allocator &alloc, size_type n) |
Allocates and construct an array of type T . More... | |
template<typename T > | |
static std::pointer_traits< pointer >::template rebind< T > | make_array (Allocator &alloc, size_type n, const T ©) |
Allocates and construct an array of type T . More... | |
The allocator_traits class template provides a standardized way to access allocator functionality.
This will infer defaults for any optional values that may not be present in the allocator
Allocator | the allocator type. Must satisfy Allocator concept |
Definition at line 81 of file allocator_traits.hpp.
using bit::memory::allocator_traits< Allocator >::pointer_rebind = typename detail::allocator_pointer_rebind<Allocator,T>::type |
Rebinds a pointer to the new pointer type.
T | the type to rebind the pointer to |
Definition at line 104 of file allocator_traits.hpp.
|
static |
Allocates memory of at least size
bytes, aligned to align
boundary.
On failure, this function may throw or invoke the out_of_memory handler before returning nullptr
alloc | the allocator to allocate from |
hint | pointer to a nearby memory location to allocate near |
size | the size of the allocation |
align | the alignment of the allocation |
|
static |
Allocates memory of at least size
bytes, aligned to align
boundary.
On failure, this function may throw or invoke the out_of_memory handler before returning nullptr
alloc | the allocator to allocate from |
hint | pointer to a nearby memory location to allocate near |
size | the size of the allocation |
align | the alignment of the allocation |
|
static |
Constructs an instance of T
at address p
with args
.
T | the type to construct |
alloc | the allocator to use for construction |
p | the pointer to the memory to construct at |
args | the arguments to forward to T's constructor |
|
static |
Deallocates a pointer previously allocated with allocate
or try_allocate.
alloc | the allocator to allocate from |
p | the pointer to deallocate |
size | the size of the allocation |
|
static |
Deallocates all memory from the given allocator.
This is only enabled if the underlying allocator supports it
alloc | the allocator to deallocate everything from |
|
static |
Destroys the instance at p
by invoking the destructor.
alloc | the allocator to use for destruction |
p | the pointer to destroy |
|
static |
Disposes of the given type T
.
This calls T's destructor, and then deallocates it with alloc
alloc | the allocater to use for deallocation |
p | to the type to destroy |
|
static |
Disposes of the given array of T.
This calls the destructor of each T, and then deallocates it with alloc
T
. Additionally, casting an array to a different type is usually UB anyway.alloc | the allocater to use for deallocation |
pointer | to the type to destroy |
|
static |
Expands the memory addres located at p
to contain new_size
bytes.
This function returns a boolean indicating whether the memory region was able to be expanded to contain the new size. If the region could not contain the new size, nothing is changed, and false
is returned.
Allocator
is to simply do nothing and return false
alloc | the allocator to use for expansion |
p | the pointer to expand |
new_size | the new size to expand to |
true
if the memory region was expanded, false
otherwise
|
staticnoexcept |
Gets the name of the specified allocator.
typeid(Allocator)
.name()alloc | the allocator to get the name of |
|
staticnoexcept |
Determines if an allocator is unbounded.
The default behavior is to check for if max_size()
returns the largest possible value for size_type
.
alloc | the allocato to check |
true
if alloc
is unbounded
|
static |
Allocates and constructs a type T
with the arguments args
.
T | the type to construct |
alloc | the allocator to use for construction |
args | the arguments to forward to T's constructor |
|
static |
Allocates and construct an array of type T
.
T | the type to construct |
alloc | the allocator to use for construction |
n | the size of the array |
copy | an instance to copy to each array entry |
|
static |
Allocates and construct an array of type T
.
T | the type to construct |
alloc | the allocator to use for construction |
n | the size of the array |
copy | an instance to copy to each array entry |
|
staticnoexcept |
Gets the maximum size allocateable from this allocator.
alloc | the allocator to get the max size from |
|
staticnoexcept |
Gets the minimum size allocateable from this allocator.
alloc | the allocator to get the min size from |
|
staticnoexcept |
Checks if the given allocator is known to own the specified pointer p
.
alloc.owns(p)
. It is undefined behavior to invoke this if Allocator::owns
is not defined; branches should instead be taken by using knows_ownershipalloc | the allocator |
p | the pointer |
|
staticnoexcept |
Converts a reference to an entry into a pointer used by this allocator.
This will attempt to call Allocator::pointer_to
, if it exists, or std::pointer_traits::pointer_to
if it doesn't
alloc | the allocator to use |
x | the value |
size_type bit::memory::allocator_traits< Allocator >::recommended_allocation_size | ( | const Allocator & | alloc, |
size_type | requested | ||
) |
Determines the recommended allocation size of requested
bytes from the given allocator.
alloc.recommended_allocation_size(requested)
if it is defined for the specified Allocator – otherwise it defaults to rounding 'requested' up to the next aligned valuealloc | the allocator |
requested | the amount of requested bytes |
|
staticnoexcept |
Converts a pointer from this allocator into a reference.
This will attempt to call Allocator::to_address
, if it exists, *std::pointer_traits::to_address
if it doesn't, and fall back to recursively dereferencing with operator->()
until it results in a pointer otherwise.
alloc | the allocator to use |
p | the pointer |
|
staticnoexcept |
Attempts to allocate memory of at least size
bytes, aligned to align
boundary.
On failure, this function returns nullptr
alloc | the allocator to allocate from |
hint | pointer to a nearby memory location to allocate near |
size | the size of the allocation |
align | the alignment of the allocation |
|
staticnoexcept |
Attempts to allocate memory of at least size
bytes, aligned to align
boundary.
On failure, this function returns nullptr
alloc | the allocator to allocate from |
hint | pointer to a nearby memory location to allocate near |
size | the size of the allocation |
align | the alignment of the allocation |