MySQL 8.0.39
Source Code Documentation
Malloc_allocator< T > Class Template Reference

Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free. More...

#include <malloc_allocator.h>

Classes

struct  rebind
 

Public Types

typedef T value_type
 
typedef size_t size_type
 
typedef ptrdiff_t difference_type
 
typedef T * pointer
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 

Public Member Functions

pointer address (reference r) const
 
const_pointer address (const_reference r) const
 
 Malloc_allocator (PSI_memory_key key)
 
template<class U >
 Malloc_allocator (const Malloc_allocator< U > &other)
 
template<class U >
Malloc_allocatoroperator= (const Malloc_allocator< U > &other)
 
pointer allocate (size_type n, const_pointer hint=nullptr)
 
void deallocate (pointer p, size_type)
 
template<class U , class... Args>
void construct (U *p, Args &&... args)
 
void destroy (pointer p)
 
size_type max_size () const
 
PSI_memory_key psi_key () const
 

Private Attributes

PSI_memory_key m_key
 

Detailed Description

template<class T = void *>
class Malloc_allocator< T >

Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.

This allows for P_S instrumentation of memory allocation done by internally by STL container classes.

Example usage: vector<int, Malloc_allocator<int>> v((Malloc_allocator<int>(PSI_NOT_INSTRUMENTED)));

If the type is complicated, you can just write Malloc_allocator<>(psi_key) as a shorthand for Malloc_allocator<My_complicated_type>(psi_key), as all Malloc_allocator instances are implicitly convertible to each other and there is a default template parameter.

Note
allocate() throws std::bad_alloc() similarly to the default STL memory allocator. This is necessary - STL functions which allocates memory expects it. Otherwise these functions will try to use the memory, leading to segfaults if memory allocation was not successful.
This allocator cannot be used for std::basic_string with RHEL 6/7 because of this bug: https://bugzilla.redhat.com/show_bug.cgi?id=1546704 "Define _GLIBCXX_USE_CXX11_ABI gets ignored by gcc in devtoolset-7"

Member Typedef Documentation

◆ const_pointer

template<class T = void *>
typedef const T* Malloc_allocator< T >::const_pointer

◆ const_reference

template<class T = void *>
typedef const T& Malloc_allocator< T >::const_reference

◆ difference_type

template<class T = void *>
typedef ptrdiff_t Malloc_allocator< T >::difference_type

◆ pointer

template<class T = void *>
typedef T* Malloc_allocator< T >::pointer

◆ reference

template<class T = void *>
typedef T& Malloc_allocator< T >::reference

◆ size_type

template<class T = void *>
typedef size_t Malloc_allocator< T >::size_type

◆ value_type

template<class T = void *>
typedef T Malloc_allocator< T >::value_type

Constructor & Destructor Documentation

◆ Malloc_allocator() [1/2]

template<class T = void *>
Malloc_allocator< T >::Malloc_allocator ( PSI_memory_key  key)
inlineexplicit

◆ Malloc_allocator() [2/2]

template<class T = void *>
template<class U >
Malloc_allocator< T >::Malloc_allocator ( const Malloc_allocator< U > &  other)
inline

Member Function Documentation

◆ address() [1/2]

template<class T = void *>
const_pointer Malloc_allocator< T >::address ( const_reference  r) const
inline

◆ address() [2/2]

template<class T = void *>
pointer Malloc_allocator< T >::address ( reference  r) const
inline

◆ allocate()

template<class T = void *>
pointer Malloc_allocator< T >::allocate ( size_type  n,
const_pointer  hint = nullptr 
)
inline

◆ construct()

template<class T = void *>
template<class U , class... Args>
void Malloc_allocator< T >::construct ( U p,
Args &&...  args 
)
inline

◆ deallocate()

template<class T = void *>
void Malloc_allocator< T >::deallocate ( pointer  p,
size_type   
)
inline

◆ destroy()

template<class T = void *>
void Malloc_allocator< T >::destroy ( pointer  p)
inline

◆ max_size()

template<class T = void *>
size_type Malloc_allocator< T >::max_size ( ) const
inline

◆ operator=()

template<class T = void *>
template<class U >
Malloc_allocator & Malloc_allocator< T >::operator= ( const Malloc_allocator< U > &  other)
inline

◆ psi_key()

template<class T = void *>
PSI_memory_key Malloc_allocator< T >::psi_key ( ) const
inline

Member Data Documentation

◆ m_key

template<class T = void *>
PSI_memory_key Malloc_allocator< T >::m_key
private

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