MySQL  8.0.18
Source Code Documentation
ut_allocator< T > Class Template Reference

Allocator class for allocating memory from inside std::* containers. More...

#include <ut0new.h>

Classes

struct  rebind
 

Public Types

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

Public Member Functions

 ut_allocator (PSI_memory_key key=PSI_NOT_INSTRUMENTED)
 Default constructor. More...
 
template<class U >
 ut_allocator (const ut_allocator< U > &other)
 Constructor from allocator of another type. More...
 
ut_allocatorset_oom_not_fatal ()
 When out of memory (OOM) happens, report error and do not make it fatal. More...
 
bool is_oom_fatal () const
 Check if allocation failure is a fatal error. More...
 
PSI_memory_key get_mem_key () const
 Get the performance schema key to use for tracing allocations. More...
 
size_type max_size () const
 Return the maximum number of objects that can be allocated by this allocator. More...
 
pointer allocate (size_type n_elements, const_pointer hint=NULL, PSI_memory_key key=PSI_NOT_INSTRUMENTED, bool set_to_zero=false, bool throw_on_error=true)
 Allocate a chunk of memory that can hold 'n_elements' objects of type 'T' and trace the allocation. More...
 
void deallocate (pointer ptr, size_type n_elements=0)
 Free a memory allocated by allocate() and trace the deallocation. More...
 
void construct (pointer p, const T &val)
 Create an object of type 'T' using the value 'val' over the memory pointed by 'p'. More...
 
void destroy (pointer p)
 Destroy an object pointed by 'p'. More...
 
pointer address (reference x) const
 Return the address of an object. More...
 
const_pointer address (const_reference x) const
 Return the address of a const object. More...
 
pointer reallocate (void *ptr, size_type n_elements, PSI_memory_key key)
 realloc(3)-like method. More...
 
pointer new_array (size_type n_elements, PSI_memory_key key)
 Allocate, trace the allocation and construct 'n_elements' objects of type 'T'. More...
 
void delete_array (T *ptr)
 Destroy, deallocate and trace the deallocation of an array created by new_array(). More...
 
pointer allocate_large (size_type n_elements, ut_new_pfx_t *pfx)
 Allocate a large chunk of memory that can hold 'n_elements' objects of type 'T' and trace the allocation. More...
 
void deallocate_large (pointer ptr, const ut_new_pfx_t *pfx)
 Free a memory allocated by allocate_large() and trace the deallocation. More...
 

Private Member Functions

size_type n_elements_allocated (const_pointer ptr)
 Retrieve the size of a memory block allocated by new_array(). More...
 
void allocate_trace (size_t size, PSI_memory_key key, ut_new_pfx_t *pfx)
 Trace a memory allocation. More...
 
void deallocate_trace (const ut_new_pfx_t *pfx)
 Trace a memory deallocation. More...
 
template<class U >
void operator= (const ut_allocator< U > &)
 

Private Attributes

PSI_memory_key m_key
 Performance schema key. More...
 
bool m_oom_fatal
 A flag to indicate whether out of memory (OOM) error is considered fatal. More...
 

Detailed Description

template<class T>
class ut_allocator< T >

Allocator class for allocating memory from inside std::* containers.

Member Typedef Documentation

◆ const_pointer

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

◆ const_reference

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

◆ difference_type

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

◆ pointer

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

◆ reference

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

◆ size_type

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

◆ value_type

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

Constructor & Destructor Documentation

◆ ut_allocator() [1/2]

template<class T>
ut_allocator< T >::ut_allocator ( PSI_memory_key  key = PSI_NOT_INSTRUMENTED)
inlineexplicit

Default constructor.

Parameters
[in]keyperformance schema key.

◆ ut_allocator() [2/2]

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

Constructor from allocator of another type.

Parameters
[in]otherthe allocator to copy.

Member Function Documentation

◆ address() [1/2]

template<class T>
pointer ut_allocator< T >::address ( reference  x) const
inline

Return the address of an object.

◆ address() [2/2]

template<class T>
const_pointer ut_allocator< T >::address ( const_reference  x) const
inline

Return the address of a const object.

◆ allocate()

template<class T>
pointer ut_allocator< T >::allocate ( size_type  n_elements,
const_pointer  hint = NULL,
PSI_memory_key  key = PSI_NOT_INSTRUMENTED,
bool  set_to_zero = false,
bool  throw_on_error = true 
)
inline

Allocate a chunk of memory that can hold 'n_elements' objects of type 'T' and trace the allocation.

If the allocation fails this method may throw an exception. This is mandated by the standard and if it returns NULL instead, then STL containers that use it (e.g. std::vector) may get confused. After successful allocation the returned pointer must be passed to ut_allocator::deallocate() when no longer needed.

Parameters
[in]n_elementsnumber of elements
[in]hintpointer to a nearby memory location, unused by this implementation
[in]keyperformance schema key
[in]set_to_zeroif true, then the returned memory is initialized with 0x0 bytes.
[in]throw_on_errorif true, then exception is throw on allocation failure
Returns
pointer to the allocated memory

◆ allocate_large()

template<class T>
pointer ut_allocator< T >::allocate_large ( size_type  n_elements,
ut_new_pfx_t pfx 
)
inline

Allocate a large chunk of memory that can hold 'n_elements' objects of type 'T' and trace the allocation.

Parameters
[in]n_elementsnumber of elements
[out]pfxstorage for the description of the allocated memory. The caller must provide space for this one and keep it until the memory is no longer needed and then pass it to deallocate_large().
Returns
pointer to the allocated memory or NULL

◆ allocate_trace()

template<class T>
void ut_allocator< T >::allocate_trace ( size_t  size,
PSI_memory_key  key,
ut_new_pfx_t pfx 
)
inlineprivate

Trace a memory allocation.

Parameters
[in]sizenumber of bytes that were allocated
[in]keyPerformance Schema key
[out]pfxplaceholder to store the info which will be needed when freeing the memory

◆ construct()

template<class T>
void ut_allocator< T >::construct ( pointer  p,
const T &  val 
)
inline

Create an object of type 'T' using the value 'val' over the memory pointed by 'p'.

◆ deallocate()

template<class T>
void ut_allocator< T >::deallocate ( pointer  ptr,
size_type  n_elements = 0 
)
inline

Free a memory allocated by allocate() and trace the deallocation.

Parameters
[in,out]ptrpointer to memory to free
[in]n_elementsnumber of elements allocated (unused)

◆ deallocate_large()

template<class T>
void ut_allocator< T >::deallocate_large ( pointer  ptr,
const ut_new_pfx_t pfx 
)
inline

Free a memory allocated by allocate_large() and trace the deallocation.

Parameters
[in,out]ptrpointer to memory to free
[in]pfxdescriptor of the memory, as returned by allocate_large().

◆ deallocate_trace()

template<class T>
void ut_allocator< T >::deallocate_trace ( const ut_new_pfx_t pfx)
inlineprivate

Trace a memory deallocation.

Parameters
[in]pfxinfo for the deallocation

◆ delete_array()

template<class T>
void ut_allocator< T >::delete_array ( T *  ptr)
inline

Destroy, deallocate and trace the deallocation of an array created by new_array().

Parameters
[in,out]ptrpointer to the first object in the array

◆ destroy()

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

Destroy an object pointed by 'p'.

◆ get_mem_key()

template<class T>
PSI_memory_key ut_allocator< T >::get_mem_key ( ) const
inline

Get the performance schema key to use for tracing allocations.

Returns
performance schema key

◆ is_oom_fatal()

template<class T>
bool ut_allocator< T >::is_oom_fatal ( ) const
inline

Check if allocation failure is a fatal error.

Returns
true if allocation failure is fatal, false otherwise.

◆ max_size()

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

Return the maximum number of objects that can be allocated by this allocator.

◆ n_elements_allocated()

template<class T>
size_type ut_allocator< T >::n_elements_allocated ( const_pointer  ptr)
inlineprivate

Retrieve the size of a memory block allocated by new_array().

Parameters
[in]ptrpointer returned by new_array().
Returns
size of memory block

◆ new_array()

template<class T>
pointer ut_allocator< T >::new_array ( size_type  n_elements,
PSI_memory_key  key 
)
inline

Allocate, trace the allocation and construct 'n_elements' objects of type 'T'.

If the allocation fails or if some of the constructors throws an exception, then this method will return NULL. It does not throw exceptions. After successful completion the returned pointer must be passed to delete_array() when no longer needed.

Parameters
[in]n_elementsnumber of elements to allocate
[in]keyPerformance schema key to allocate under
Returns
pointer to the first allocated object or NULL

◆ operator=()

template<class T>
template<class U >
void ut_allocator< T >::operator= ( const ut_allocator< U > &  )
private

◆ reallocate()

template<class T>
pointer ut_allocator< T >::reallocate ( void *  ptr,
size_type  n_elements,
PSI_memory_key  key 
)
inline

realloc(3)-like method.

The passed in ptr must have been returned by allocate() and the pointer returned by this method must be passed to deallocate() when no longer needed.

Parameters
[in,out]ptrold pointer to reallocate
[in]n_elementsnew number of elements to allocate
[in]keyPerformance schema key to allocate under
Returns
newly allocated memory

◆ set_oom_not_fatal()

template<class T>
ut_allocator& ut_allocator< T >::set_oom_not_fatal ( )
inline

When out of memory (OOM) happens, report error and do not make it fatal.

Returns
a reference to the allocator.

Member Data Documentation

◆ m_key

template<class T>
PSI_memory_key ut_allocator< T >::m_key
private

Performance schema key.

◆ m_oom_fatal

template<class T>
bool ut_allocator< T >::m_oom_fatal
private

A flag to indicate whether out of memory (OOM) error is considered fatal.

If true, it is fatal.


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