MySQL 9.1.0
Source Code Documentation
Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN > Class Template Reference

Stateless_allocator is a C++ STL memory allocator skeleton based on Malloc_allocator, which assumes that a global free function can be used to allocate and deallocate memory, so that no state need to be kept by the allocator object. More...

#include <stateless_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
 
template<class T_ >
using Stateless_allocator_type = Stateless_allocator< T_, ALLOC_FUN, DEALLOC_FUN >
 

Public Member Functions

 Stateless_allocator ()=default
 
pointer address (reference r) const
 
const_pointer address (const_reference r) const
 
template<class U >
 Stateless_allocator (const Stateless_allocator_type< U > &)
 
template<class U >
Stateless_allocatoroperator= (const Stateless_allocator_type< U > &)
 
pointer allocate (size_type n, const_pointer hint=nullptr)
 
void deallocate (pointer p, size_type n)
 
template<class U , class... Args>
void construct (U *p, Args &&...args)
 
void destroy (pointer p)
 
size_type max_size () const
 

Detailed Description

template<class T, class ALLOC_FUN, class DEALLOC_FUN = My_free_functor>
class Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >

Stateless_allocator is a C++ STL memory allocator skeleton based on Malloc_allocator, which assumes that a global free function can be used to allocate and deallocate memory, so that no state need to be kept by the allocator object.

The allocation and deallocation functions must be provided as callable types (aka functors) which have no state and can be default constructed.

Example usage:

struct My_psi_key_alloc
{
  void* operator(size_t s)()
  {
     return my_malloc(My_psi_key, s, MYF(MY_WME | ME_FATALERROR));
  }
};

template <class T>
using My_psi_key_allocator =
     Stateless_allocator<T, My_psi_key_alloc>;

template < template<class T> class Allocator >
using default_string=
      std::basic_string<char, std::char_traits<char>, Allocator<char> >;


typedef default_string<My_psi_key_allocator> My_psi_key_str;

My_psi_key_str x("foobar");

Since a Stateless_allocator instance is always default-constructible, it can also be used to create instances of std::basic_string, even with compilers that have this libstd++ bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56437 "basic_string assumes that allocators are default-constructible".

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.

Member Typedef Documentation

◆ const_pointer

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef const T* Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::const_pointer

◆ const_reference

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef const T& Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::const_reference

◆ difference_type

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef ptrdiff_t Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::difference_type

◆ pointer

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef T* Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::pointer

◆ reference

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef T& Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::reference

◆ size_type

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef size_t Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::size_type

◆ Stateless_allocator_type

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
template<class T_ >
using Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::Stateless_allocator_type = Stateless_allocator<T_, ALLOC_FUN, DEALLOC_FUN>

◆ value_type

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
typedef T Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::value_type

Constructor & Destructor Documentation

◆ Stateless_allocator() [1/2]

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::Stateless_allocator ( )
default

◆ Stateless_allocator() [2/2]

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
template<class U >
Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::Stateless_allocator ( const Stateless_allocator_type< U > &  )
inline

Member Function Documentation

◆ address() [1/2]

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
const_pointer Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::address ( const_reference  r) const
inline

◆ address() [2/2]

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
pointer Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::address ( reference  r) const
inline

◆ allocate()

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
pointer Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::allocate ( size_type  n,
const_pointer  hint = nullptr 
)
inline

◆ construct()

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
template<class U , class... Args>
void Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::construct ( U p,
Args &&...  args 
)
inline

◆ deallocate()

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
void Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::deallocate ( pointer  p,
size_type  n 
)
inline

◆ destroy()

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
void Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::destroy ( pointer  p)
inline

◆ max_size()

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
size_type Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::max_size ( ) const
inline

◆ operator=()

template<class T , class ALLOC_FUN , class DEALLOC_FUN = My_free_functor>
template<class U >
Stateless_allocator & Stateless_allocator< T, ALLOC_FUN, DEALLOC_FUN >::operator= ( const Stateless_allocator_type< U > &  )
inline

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