MySQL 8.0.39
Source Code Documentation
|
#include <aligned_alloc.h>
Public Types | |
using | data_segment_ptr = void * |
Alias that we will be using to denote ptr to DATA segment. More... | |
Static Public Member Functions | |
template<bool Zero_initialized> | |
static std::pair< data_segment_ptr, std::size_t > | alloc (std::size_t size, std::size_t alignment) noexcept |
Dynamically allocates storage of given size and at the address aligned to the requested alignment. More... | |
static void | free (void *ptr) noexcept |
Releases storage allocated through alloc(). More... | |
Static Public Attributes | |
static constexpr uint32_t | metadata_size = alignof(max_align_t) |
Block of memory returned by this functor will have an additional (metadata) segment (at no additional cost of higher memory consumption) which is guaranteed to be this big, and which can be used to store whatever arbitrary data. More... | |
using ut::detail::Aligned_alloc_impl::data_segment_ptr = void * |
Alias that we will be using to denote ptr to DATA segment.
|
inlinestaticnoexcept |
Dynamically allocates storage of given size and at the address aligned to the requested alignment.
It is guaranteed that storage allocated by this functor is always (size + alignment) big and that there is always alignof(std::max_align_t) spare bytes within that segment which can be freely used. This means that pointer which is returned by this function can always be safely reversed by alignof(std::max_align_t) bytes and hence make this sub-segment accessible to any subsequent implementation.
Reversing the pointer for a value which is bigger than alignof(std::max_align_t) bytes is in certain cases possible and can be checked by inspecting the returned offset value. Some more specialized implementations can take advantage of that fact too.
This property is very important because it can be taken advantage of by other implementations so they are able to store whatever metadata they would like into this segment of alignof(std::max_align_t) bytes, or FWIW (pointer - offset) bytes in more specialized cases.
For example, let's say that size=10, alignment=32, and underlying allocation function used by this function implementation returns a pointer at address 128. This address must be a multiple of alignof(std::max_align_t) which in this example is 16.
128 144 160 170
DATA is an actual data which has been requested with given size (10) and alignment (32). META is the alignof(std::max_align_t) segment that can always be freely used by other implementations. VARLEN is the leftover variable-length segment that specialized implementations can further make use of by deducing its size from returned offset.
See Aligned_alloc and Aligned_alloc_arr implementations to see an example of how META segment can be used.
[in] | size | Size of storage (in bytes) requested to be allocated. |
[in] | alignment | Alignment requirement for storage to be allocated. Must be power of two and larger than alignof(std::max_align_t). |
|
inlinestaticnoexcept |
Releases storage allocated through alloc().
[in] | ptr | data_segment_pointer decreased by offset bytes. Both are obtained through alloc(). |
|
staticconstexpr |
Block of memory returned by this functor will have an additional (metadata) segment (at no additional cost of higher memory consumption) which is guaranteed to be this big, and which can be used to store whatever arbitrary data.
See Aligned_alloc and Aligned_alloc_arr for exemplary usages of it.