MySQL 9.0.0
Source Code Documentation
Mem_root_allocator< T > Class Template Reference

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

#include <mem_root_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
 
 Mem_root_allocator (MEM_ROOT *memroot)
 
 Mem_root_allocator ()
 
template<class U >
 Mem_root_allocator (const Mem_root_allocator< U > &other)
 
template<class U >
Mem_root_allocatoroperator= (const Mem_root_allocator< U > &other)
 
pointer allocate (size_type n, const_pointer hint=nullptr)
 
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 Mem_root_allocator< T >

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

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

Example of use: vector<int, Mem_root_allocator<int> > v((Mem_root_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 Mem_root_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* Mem_root_allocator< T >::const_pointer

◆ const_reference

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

◆ difference_type

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

◆ pointer

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

◆ reference

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

◆ size_type

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

◆ value_type

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

Constructor & Destructor Documentation

◆ Mem_root_allocator() [1/3]

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

◆ Mem_root_allocator() [2/3]

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

◆ Mem_root_allocator() [3/3]

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

Member Function Documentation

◆ address() [1/2]

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

◆ address() [2/2]

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

◆ allocate()

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

◆ construct()

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

◆ deallocate()

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

◆ destroy()

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

◆ max_size()

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

◆ memroot()

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

◆ operator=()

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

Member Data Documentation

◆ m_memroot

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

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