MySQL 9.6.0
Source Code Documentation
mysql::allocators::Allocator< T > Class Template Reference

Allocator using a Memory_resource to do the allocation. More...

#include <allocator.h>

Public Types

using value_type = T
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using propagate_on_container_move_assignment = std::true_type
 On move-assignment for containers using this allocator, make the target container inherit the allocator and reuse the memory from the source container. More...
 
using propagate_on_container_copy_assignment = std::false_type
 On copy-assignment for containers using this allocator, make the target container preserve its existing allocator and reuse its own memory if possible. More...
 

Public Member Functions

 Allocator (Memory_resource memory_resource=Memory_resource()) noexcept
 Construct a new Allocator using the given Memory_resource. More...
 
template<class U >
constexpr Allocator (const Allocator< U > &other) noexcept
 Implicit conversion from other instance. More...
 
constexpr Allocator (const Allocator &other) noexcept=default
 
constexpr Allocatoroperator= (const Allocator &other) noexcept=default
 
constexpr Allocator (Allocator &&other) noexcept
 
constexpr Allocatoroperator= (Allocator &&other) noexcept
 
 ~Allocator () noexcept=default
 
constexpr Tallocate (size_type n)
 Use the Memory_resource to allocate the given number of elements of type T. More...
 
constexpr void deallocate (T *p, size_type size)
 Use the Memory_resource to deallocate the given pointer. More...
 
std::function< void(T *)> get_deleter ()
 Return a Deleter function for objects allocated by this class. More...
 
const Memory_resourceget_memory_resource () const
 Return a reference to the underlying Memory_resource object. More...
 

Private Attributes

Memory_resource m_memory_resource
 The underlying Memory_resource object. More...
 

Detailed Description

template<class T>
class mysql::allocators::Allocator< T >

Allocator using a Memory_resource to do the allocation.

A library that allocates memory should allow the user to pass a Memory_resource object which defaults to a default-constructed instance, Memory_resource(). Internally it should create the Allocator<T> classes it needs (possibly several, for different classes T), using the given Memory_resource object. Users of the library outside the server should just use the default Memory_resource. Users of the library inside the server should setup a PSI key and pass the result from psi_memory_resource(Key) to the library.

Member Typedef Documentation

◆ difference_type

template<class T >
using mysql::allocators::Allocator< T >::difference_type = std::ptrdiff_t

◆ propagate_on_container_copy_assignment

template<class T >
using mysql::allocators::Allocator< T >::propagate_on_container_copy_assignment = std::false_type

On copy-assignment for containers using this allocator, make the target container preserve its existing allocator and reuse its own memory if possible.

◆ propagate_on_container_move_assignment

template<class T >
using mysql::allocators::Allocator< T >::propagate_on_container_move_assignment = std::true_type

On move-assignment for containers using this allocator, make the target container inherit the allocator and reuse the memory from the source container.

◆ size_type

template<class T >
using mysql::allocators::Allocator< T >::size_type = std::size_t

◆ value_type

template<class T >
using mysql::allocators::Allocator< T >::value_type = T

Constructor & Destructor Documentation

◆ Allocator() [1/4]

template<class T >
mysql::allocators::Allocator< T >::Allocator ( Memory_resource  memory_resource = Memory_resource())
inlineexplicitnoexcept

Construct a new Allocator using the given Memory_resource.

Parameters
memory_resourceThe memory resource. By default, this uses a default-constructed Memory_resource, so it uses std::malloc and std::free for allocations.

◆ Allocator() [2/4]

template<class T >
template<class U >
constexpr mysql::allocators::Allocator< T >::Allocator ( const Allocator< U > &  other)
inlineconstexprnoexcept

Implicit conversion from other instance.

This is required to exist and be implicit by the Windows implementation of std::vector.

◆ Allocator() [3/4]

template<class T >
constexpr mysql::allocators::Allocator< T >::Allocator ( const Allocator< T > &  other)
constexprdefaultnoexcept

◆ Allocator() [4/4]

template<class T >
constexpr mysql::allocators::Allocator< T >::Allocator ( Allocator< T > &&  other)
inlineconstexprnoexcept

◆ ~Allocator()

template<class T >
mysql::allocators::Allocator< T >::~Allocator ( )
defaultnoexcept

Member Function Documentation

◆ allocate()

template<class T >
constexpr T * mysql::allocators::Allocator< T >::allocate ( size_type  n)
inlineconstexpr

Use the Memory_resource to allocate the given number of elements of type T.

Parameters
nThe number of elements.
Returns
The new pointer.
Exceptions
std::bad_allocon out of memory conditions.

◆ deallocate()

template<class T >
constexpr void mysql::allocators::Allocator< T >::deallocate ( T p,
size_type  size 
)
inlineconstexpr

Use the Memory_resource to deallocate the given pointer.

Parameters
pThe pointer to deallocate.
sizeUnused.

◆ get_deleter()

template<class T >
std::function< void(T *)> mysql::allocators::Allocator< T >::get_deleter ( )
inline

Return a Deleter function for objects allocated by this class.

Such a Deleter must be specified when constructing a smart pointer to an object created by this Allocator, for example:

Allocator<T> allocator(some_memory_resource);
T *obj = allocator.allocate(1);
std::shared_ptr<T> ptr(obj, allocator.get_deleter());
#define T
Definition: jit_executor_value.cc:373
Return values
Deleterfunction that takes a T* as argument and uses the Memory_resource to deallocate it.

◆ get_memory_resource()

template<class T >
const Memory_resource & mysql::allocators::Allocator< T >::get_memory_resource ( ) const
inline

Return a reference to the underlying Memory_resource object.

◆ operator=() [1/2]

template<class T >
constexpr Allocator & mysql::allocators::Allocator< T >::operator= ( Allocator< T > &&  other)
inlineconstexprnoexcept

◆ operator=() [2/2]

template<class T >
constexpr Allocator & mysql::allocators::Allocator< T >::operator= ( const Allocator< T > &  other)
constexprdefaultnoexcept

Member Data Documentation

◆ m_memory_resource

template<class T >
Memory_resource mysql::allocators::Allocator< T >::m_memory_resource
private

The underlying Memory_resource object.


The documentation for this class was generated from the following file: