MySQL  8.0.16
Source Code Documentation
Memroot_allocator< T > Class Template Reference

Memroot_allocator is a C++ STL memory allocator based on MEM_ROOT. More...

#include <equi_height.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
 
 Memroot_allocator (MEM_ROOT *memroot)
 
 Memroot_allocator ()
 
template<class U >
 Memroot_allocator (const Memroot_allocator< U > &other)
 
template<class U >
Memroot_allocatoroperator= (const Memroot_allocator< U > &other)
 
pointer allocate (size_type n, const_pointer hint=0)
 
void deallocate (pointer, size_type)
 
template<class U , class... Args>
void construct (U *p, Args &&... args)
 
void destroy (pointer p)
 
size_type max_size () const
 
MEM_ROOTmemroot () const
 

Private Attributes

MEM_ROOTm_memroot
 

Detailed Description

template<class T>
class Memroot_allocator< T >

Memroot_allocator is a C++ STL memory allocator based on MEM_ROOT.

No deallocation is done by this allocator. Calling init_sql_alloc() and free_root() on the supplied MEM_ROOT is the responsibility of the caller. Do not call free_root() until the destructor of any objects using this allocator has completed. This includes iterators.

Example of use: vector<int, Memroot_allocator<int> > v((Memroot_allocator<int>(&mem_root)));

Note
allocate() throws std::bad_alloc() similarly to the default STL memory allocator. This is necessary - STL functions which allocate memory expect it. Otherwise these functions will try to use the memory, leading to seg faults 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"
C++98 says that STL implementors can assume that allocator objects of the same type always compare equal. This will only be the case for two Memroot_allocators that use the same MEM_ROOT. Care should be taken when this is not the case. Especially:
  • Using list::splice() on two lists with allocators using two different MEM_ROOTs causes undefined behavior. Most implementations seem to give runtime errors in such cases.
  • swap() on two collections with allocators using two different MEM_ROOTs is not well defined. At least some implementations also swap allocators, but this should not be depended on.

Member Typedef Documentation

◆ const_pointer

template<class T>
typedef const T* Memroot_allocator< T >::const_pointer

◆ const_reference

template<class T>
typedef const T& Memroot_allocator< T >::const_reference

◆ difference_type

template<class T>
typedef ptrdiff_t Memroot_allocator< T >::difference_type

◆ pointer

template<class T>
typedef T* Memroot_allocator< T >::pointer

◆ reference

template<class T>
typedef T& Memroot_allocator< T >::reference

◆ size_type

template<class T>
typedef size_t Memroot_allocator< T >::size_type

◆ value_type

template<class T>
typedef T Memroot_allocator< T >::value_type

Constructor & Destructor Documentation

◆ Memroot_allocator() [1/3]

template<class T>
Memroot_allocator< T >::Memroot_allocator ( MEM_ROOT memroot)
inlineexplicit

◆ Memroot_allocator() [2/3]

template<class T>
Memroot_allocator< T >::Memroot_allocator ( )
inlineexplicit

◆ Memroot_allocator() [3/3]

template<class T>
template<class U >
Memroot_allocator< T >::Memroot_allocator ( const Memroot_allocator< U > &  other)
inline

Member Function Documentation

◆ address() [1/2]

template<class T>
pointer Memroot_allocator< T >::address ( reference  r) const
inline

◆ address() [2/2]

template<class T>
const_pointer Memroot_allocator< T >::address ( const_reference  r) const
inline

◆ allocate()

template<class T>
pointer Memroot_allocator< T >::allocate ( size_type  n,
const_pointer  hint = 0 
)
inline

◆ construct()

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

◆ deallocate()

template<class T>
void Memroot_allocator< T >::deallocate ( pointer  ,
size_type   
)
inline

◆ destroy()

template<class T>
void Memroot_allocator< T >::destroy ( pointer  p)
inline

◆ max_size()

template<class T>
size_type Memroot_allocator< T >::max_size ( ) const
inline

◆ memroot()

template<class T>
MEM_ROOT* Memroot_allocator< T >::memroot ( ) const
inline

◆ operator=()

template<class T>
template<class U >
Memroot_allocator& Memroot_allocator< T >::operator= ( const Memroot_allocator< U > &  other)
inline

Member Data Documentation

◆ m_memroot

template<class T>
MEM_ROOT* Memroot_allocator< T >::m_memroot
private

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