MySQL 8.0.39
Source Code Documentation
ut::aligned_pointer< T, Alignment > Class Template Reference

Lightweight convenience wrapper which manages dynamically allocated over-aligned type. More...

#include <ut0new.h>

Public Member Functions

 ~aligned_pointer ()
 Destructor. More...
 
template<typename... Args>
void alloc (Args &&... args)
 Allocates sufficiently large memory of dynamic storage duration to fit the instance of type T at the address which is aligned to Alignment bytes. More...
 
template<typename... Args>
void alloc_withkey (PSI_memory_key_t key, Args &&... args)
 Allocates sufficiently large memory of dynamic storage duration to fit the instance of type T at the address which is aligned to Alignment bytes. More...
 
void dealloc ()
 Invokes the destructor of instance of type T, if applicable. More...
 
 operator T* () const
 Conversion operator. More...
 

Private Attributes

T * ptr = nullptr
 

Detailed Description

template<typename T, size_t Alignment>
class ut::aligned_pointer< T, Alignment >

Lightweight convenience wrapper which manages dynamically allocated over-aligned type.

Wrapper makes use of RAII to do the resource cleanup.

Example usage: struct My_fancy_type { My_fancy_type(int x, int y) : _x(x), _y(y) {} int _x, _y; };

aligned_pointer<My_fancy_type, 32> ptr; ptr.alloc(10, 5); My_fancy_type *p = ptr; assert(p->_x == 10 && p->_y == 5);

Template Parameters
TType to be managed.
AlignmentNumber of bytes to align the type T to.

Constructor & Destructor Documentation

◆ ~aligned_pointer()

template<typename T , size_t Alignment>
ut::aligned_pointer< T, Alignment >::~aligned_pointer ( )
inline

Destructor.

Invokes destructor of the underlying instance of type T. Releases dynamically allocated resources, if there had been left any.

Member Function Documentation

◆ alloc()

template<typename T , size_t Alignment>
template<typename... Args>
void ut::aligned_pointer< T, Alignment >::alloc ( Args &&...  args)
inline

Allocates sufficiently large memory of dynamic storage duration to fit the instance of type T at the address which is aligned to Alignment bytes.

Constructs the instance of type T with given Args.

Underlying instance of type T is accessed through the conversion operator.

Parameters
[in]argsAny number and type of arguments that type T can be constructed with.

◆ alloc_withkey()

template<typename T , size_t Alignment>
template<typename... Args>
void ut::aligned_pointer< T, Alignment >::alloc_withkey ( PSI_memory_key_t  key,
Args &&...  args 
)
inline

Allocates sufficiently large memory of dynamic storage duration to fit the instance of type T at the address which is aligned to Alignment bytes.

Constructs the instance of type T with given Args. Instruments the memory with given PSI memory key in case PFS memory support is enabled.

Underlying instance of type T is accessed through the conversion operator.

Parameters
[in]keyPSI memory key to be used for PFS memory instrumentation.
[in]argsAny number and type of arguments that type T can be constructed with.

◆ dealloc()

template<typename T , size_t Alignment>
void ut::aligned_pointer< T, Alignment >::dealloc ( )
inline

Invokes the destructor of instance of type T, if applicable.

Releases the resources previously allocated with alloc().

◆ operator T*()

template<typename T , size_t Alignment>
ut::aligned_pointer< T, Alignment >::operator T* ( ) const
inline

Conversion operator.

Used for accessing the underlying instance of type T.

Member Data Documentation

◆ ptr

template<typename T , size_t Alignment>
T* ut::aligned_pointer< T, Alignment >::ptr = nullptr
private

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