![]() |
MySQL 9.2.0
Source Code Documentation
|
Allocator that allows std::* containers to manage their memory through ut::malloc* and ut::free library functions. More...
#include <ut0new.h>
Classes | |
struct | rebind |
Public Types | |
using | pointer = T * |
using | const_pointer = const T * |
using | reference = T & |
using | const_reference = const T & |
using | value_type = T |
using | size_type = size_t |
using | difference_type = ptrdiff_t |
Public Member Functions | |
allocator (PSI_memory_key key=mem_key_std) | |
Default constructor. More... | |
allocator (const allocator< T, Allocator_base > &)=default | |
allocator< T, Allocator_base > & | operator= (const allocator< T, Allocator_base > &)=default |
allocator (allocator< T, Allocator_base > &&)=default | |
allocator< T, Allocator_base > & | operator= (allocator< T, Allocator_base > &&)=default |
~allocator ()=default | |
template<typename U > | |
allocator (const allocator< U, Allocator_base > &other) | |
Copy-construct a new instance of allocator with type T by using existing instance of allocator constructed with a different type U. More... | |
bool | operator== (const ut::allocator< T, Allocator_base > &) const |
Equality of allocators instantiated with same types T. More... | |
bool | operator!= (const ut::allocator< T, Allocator_base > &other) const |
Non-equality of allocators instantiated with same types T. 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=nullptr) |
Allocates chunk of memory that can hold n_elements objects of type T. More... | |
void | deallocate (pointer ptr, size_type n_elements=0) |
Releases the memory allocated through ut::allocator<T>::allocate(). More... | |
Allocator that allows std::* containers to manage their memory through ut::malloc* and ut::free library functions.
Main purpose of this custom allocator is to instrument all of the memory allocations and deallocations that are being done by std::* containers under the hood, and have them recorded through the PFS (memory) engine.
Other than std::* containers, this allocator is of course also suitable for use in any other allocator-aware containers and/or code.
Given that ut::malloc* and ut::free library functions already handle all the PFS and non-PFS implementation bits and pieces, this allocator is a mere wrapper around them.
Example which uses default PFS key (mem_key_std) to trace all std::vector allocations and deallocations: std::vector<int, ut::allocator<int>> vec; vec.push_back(...); ... vec.push_back(...);
Example which uses user-provided PFS key to trace std::vector allocations and deallocations: ut::allocator<int> allocator(some_other_psi_key); std::vector<int, ut::allocator<int>> vec(allocator); vec.push_back(...); ... vec.push_back(...);
using ut::allocator< T, Allocator_base >::const_pointer = const T * |
using ut::allocator< T, Allocator_base >::const_reference = const T & |
using ut::allocator< T, Allocator_base >::difference_type = ptrdiff_t |
using ut::allocator< T, Allocator_base >::pointer = T * |
using ut::allocator< T, Allocator_base >::reference = T & |
using ut::allocator< T, Allocator_base >::size_type = size_t |
using ut::allocator< T, Allocator_base >::value_type = T |
|
inlineexplicit |
Default constructor.
[in] | key | performance schema key. |
|
default |
|
default |
|
default |
|
inline |
Copy-construct a new instance of allocator with type T by using existing instance of allocator constructed with a different type U.
[in] | other | the allocator to copy from. |
|
inline |
Allocates chunk of memory that can hold n_elements objects of type T.
Returned pointer is always valid. In case underlying allocation function was not able to fulfill the allocation request, this function will throw std::bad_alloc exception. After successful allocation, returned pointer must be passed back to ut::allocator<T>::deallocate() when no longer needed.
[in] | n_elements | number of elements |
[in] | hint | pointer to a nearby memory location, not used by this implementation |
|
inline |
Releases the memory allocated through ut::allocator<T>::allocate().
[in,out] | ptr | pointer to memory to free |
[in] | n_elements | number of elements allocated (unused) |
|
inline |
Return the maximum number of objects that can be allocated by this allocator.
This number is somewhat lower for PFS-enabled builds because of extra few bytes needed for PFS.
|
inline |
Non-equality of allocators instantiated with same types T.
|
default |
|
default |
|
inline |
Equality of allocators instantiated with same types T.