MySQL 8.0.40
Source Code Documentation
|
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 |
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);
T | Type to be managed. |
Alignment | Number of bytes to align the first element of array to. |
|
inline |
Destructor.
Invokes destructors of the underlying instances of type T. Releases dynamically allocated resources, if there had been left any.
|
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.
[in] | args | Any number and type of arguments that type T can be constructed with. |
|
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.
[in] | count | Number of T elements in an array. |
|
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.
[in] | key | PSI memory key to be used for PFS memory instrumentation. |
[in] | args | Any number and type of arguments that type T can be constructed with. |
|
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.
[in] | key | PSI memory key to be used for PFS memory instrumentation. |
[in] | count | Number of T elements in an array. |
|
inline |
Invokes destructors of instances of type T, if applicable.
Releases the resources previously allocated with any variant of alloc().
|
inline |
Conversion operator.
Used for accessing the underlying instances of type T.
|
private |