MySQL 8.4.0
Source Code Documentation
ut::aligned_array_pointer< T, Alignment > Class Template Reference

Lightweight convenience wrapper which manages a dynamically allocated array of over-aligned types. More...

#include <ut0new.h>

Public Member Functions

 ~aligned_array_pointer ()
 Destructor. More...
 
void alloc (Count count)
 Allocates sufficiently large memory of dynamic storage duration to fit the array of size number of elements of type T at the address which is aligned to Alignment bytes. More...
 
template<typename... Args>
void alloc (Args &&... args)
 Allocates sufficiently large memory of dynamic storage duration to fit the array of size number of elements of type T at the address which is aligned to Alignment bytes. More...
 
void alloc_withkey (PSI_memory_key_t key, Count count)
 Allocates sufficiently large memory of dynamic storage duration to fit the array of size number of elements 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 array of size number of elements of type T at the address which is aligned to Alignment bytes. More...
 
void dealloc ()
 Invokes destructors of instances 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_array_pointer< T, Alignment >

Lightweight convenience wrapper which manages a dynamically allocated array of over-aligned types.

Only the first element of an array is guaranteed to be aligned to the requested Alignment. Wrapper makes use of RAII to do the resource cleanup.

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

aligned_array_pointer<My_fancy_type, 32> ptr; ptr.alloc(3); My_fancy_type *p = ptr; assert(p[0]._x == 0 && p[0]._y == 0); assert(p[1]._x == 0 && p[1]._y == 0); assert(p[2]._x == 0 && p[2]._y == 0);

Example usage 2: aligned_array_pointer<My_fancy_type, 32> ptr; ptr.alloc<3>(1, 2, 3, 4, 5, 6); My_fancy_type *p = ptr; assert(p[0]._x == 1 && p[0]._y == 2); assert(p[1]._x == 3 && p[1]._y == 4); assert(p[2]._x == 5 && p[2]._y == 6);

Template Parameters
TType to be managed.
AlignmentNumber of bytes to align the first element of array to.

Constructor & Destructor Documentation

◆ ~aligned_array_pointer()

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

Destructor.

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

Member Function Documentation

◆ alloc() [1/2]

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

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

Constructs the size number of instances of type T, each being initialized through the means of provided Args and corresponding constructors.

Underlying instances of type T are accessed through the conversion operator.

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

◆ alloc() [2/2]

template<typename T , size_t Alignment>
void ut::aligned_array_pointer< T, Alignment >::alloc ( Count  count)
inline

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

Constructs the size number of instances of type T, each being initialized through the means of default constructor.

Underlying instances of type T are accessed through the conversion operator.

Parameters
[in]countNumber of T elements in an array.

◆ alloc_withkey() [1/2]

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

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

Constructs the size number of instances of type T, each being initialized through the means of provided Args and corresponding constructors. Instruments the memory with given PSI memory key in case PFS memory support is enabled.

Underlying instances of type T are 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.

◆ alloc_withkey() [2/2]

template<typename T , size_t Alignment>
void ut::aligned_array_pointer< T, Alignment >::alloc_withkey ( PSI_memory_key_t  key,
Count  count 
)
inline

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

Constructs the size number of instances of type T, each being initialized through the means of default constructor. Instruments the memory with given PSI memory key in case PFS memory support is enabled.

Underlying instances of type T are accessed through the conversion operator.

Parameters
[in]keyPSI memory key to be used for PFS memory instrumentation.
[in]countNumber of T elements in an array.

◆ dealloc()

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

Invokes destructors of instances of type T, if applicable.

Releases the resources previously allocated with any variant of alloc().

◆ operator T*()

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

Conversion operator.

Used for accessing the underlying instances of type T.

Member Data Documentation

◆ ptr

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

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