MySQL 8.3.0
Source Code Documentation
mysql::binlog::event::resource::Allocator< T > Class Template Reference

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

#include <allocator.h>

Classes

struct  rebind
 Rebind the allocator as requried by the Allocator named requirement. More...
 

Public Types

using value_type = T
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using reference = T &
 
using const_reference = const T &
 

Public Member Functions

 Allocator (Memory_resource memory_resource=Memory_resource())
 Construct a new Allocator using the given Memory_resource. More...
 
template<class U >
 Allocator (const Allocator< U > &other)
 Implicit conversion from other instance. More...
 
pointer allocate (size_type n, const_pointer hint=nullptr)
 Use the Memory_resource to allocate the given number of elements of type T. More...
 
void deallocate (pointer p, size_type size)
 Use the Memory_resource to deallocate the given pointer. More...
 
std::function< void(pointer)> get_deleter ()
 Return a Deleter function for objects allocated by this class. More...
 
template<class U , class... Args>
void construct (U *p, Args &&... args)
 In-place construct a new object of the given type. More...
 
void destroy (pointer p)
 Destroy an object but do not deallocate the memory it occupies. More...
 
size_type max_size () const
 The maximum number of T objects that fit in memory. More...
 
Memory_resource get_memory_resource () const
 Return the underlying Memory_resource object. More...
 

Private Attributes

const Memory_resource m_memory_resource
 The underlying Memory_resource object. More...
 

Detailed Description

template<class T>
class mysql::binlog::event::resource::Allocator< T >

Allocator using a Memory_resource to do the allocator.

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 memory_resource(Key) to the library.

Member Typedef Documentation

◆ const_pointer

template<class T >
using mysql::binlog::event::resource::Allocator< T >::const_pointer = const value_type *

◆ const_reference

template<class T >
using mysql::binlog::event::resource::Allocator< T >::const_reference = const T &

◆ difference_type

template<class T >
using mysql::binlog::event::resource::Allocator< T >::difference_type = std::ptrdiff_t

◆ pointer

template<class T >
using mysql::binlog::event::resource::Allocator< T >::pointer = value_type *

◆ reference

template<class T >
using mysql::binlog::event::resource::Allocator< T >::reference = T &

◆ size_type

template<class T >
using mysql::binlog::event::resource::Allocator< T >::size_type = std::size_t

◆ value_type

template<class T >
using mysql::binlog::event::resource::Allocator< T >::value_type = T

Constructor & Destructor Documentation

◆ Allocator() [1/2]

template<class T >
mysql::binlog::event::resource::Allocator< T >::Allocator ( Memory_resource  memory_resource = Memory_resource())
inlineexplicit

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/2]

template<class T >
template<class U >
mysql::binlog::event::resource::Allocator< T >::Allocator ( const Allocator< U > &  other)
inlineexplicit

Implicit conversion from other instance.

This is required by Windows implementation of std::vector<Allocator>.

Member Function Documentation

◆ allocate()

template<class T >
pointer mysql::binlog::event::resource::Allocator< T >::allocate ( size_type  n,
const_pointer  hint = nullptr 
)
inline

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

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

◆ construct()

template<class T >
template<class U , class... Args>
void mysql::binlog::event::resource::Allocator< T >::construct ( U p,
Args &&...  args 
)
inline

In-place construct a new object of the given type.

Parameters
pPointer to memory area where the new object will be constructed.
argsArguments to pass to the constructor.
Exceptions
std::bad_allocon out of memory conditions.

◆ deallocate()

template<class T >
void mysql::binlog::event::resource::Allocator< T >::deallocate ( pointer  p,
size_type  size 
)
inline

Use the Memory_resource to deallocate the given pointer.

Parameters
pThe pointer to deallocate.
sizeUnused.

◆ destroy()

template<class T >
void mysql::binlog::event::resource::Allocator< T >::destroy ( pointer  p)
inline

Destroy an object but do not deallocate the memory it occupies.

Parameters
pPointer to the object.

◆ get_deleter()

template<class T >
std::function< void(pointer)> mysql::binlog::event::resource::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());
Return values
Deleterfunction that takes a pointer as argument and uses the Memory_resource to deallocate it.

◆ get_memory_resource()

template<class T >
Memory_resource mysql::binlog::event::resource::Allocator< T >::get_memory_resource ( ) const
inline

Return the underlying Memory_resource object.

◆ max_size()

template<class T >
size_type mysql::binlog::event::resource::Allocator< T >::max_size ( ) const
inline

The maximum number of T objects that fit in memory.

Member Data Documentation

◆ m_memory_resource

template<class T >
const Memory_resource mysql::binlog::event::resource::Allocator< T >::m_memory_resource
private

The underlying Memory_resource object.


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