MySQL 9.1.0
Source Code Documentation
ut::detail::Alloc_arr Struct Reference

Specialization of allocation routines for non-extended alignment types but which in comparison to Alloc are providing support for arrays. More...

#include <alloc.h>

Inheritance diagram for ut::detail::Alloc_arr:
[legend]

Public Types

using datalen_t = size_t
 This is the type we will be using to store the size of an array. More...
 

Static Public Member Functions

template<bool Zero_initialized>
static void * alloc (std::size_t size) noexcept
 Sanity check so that we can be sure that our metadata segment can fit the datalen_t. More...
 
static void free (void *ptr) noexcept
 Releases storage dynamically allocated through Alloc_arr::alloc(). More...
 
static datalen_t datalen (void *ptr)
 Returns the size of an array in bytes. More...
 

Static Public Attributes

static constexpr auto metadata_len = alignof(max_align_t)
 This is how much the metadata (ALLOC-ARR-META) segment will be big. More...
 
- Static Public Attributes inherited from ut::detail::allocator_traits< false >
static constexpr auto is_pfs_instrumented_v
 

Static Private Member Functions

static void * deduce (void *ptr) noexcept
 Helper function which deduces the original pointer returned by Alloc_arr::alloc() from a pointer which is passed to us by the call-site. More...
 

Detailed Description

Specialization of allocation routines for non-extended alignment types but which in comparison to Alloc are providing support for arrays.

To provide support for arrays, these allocation routines will allocate extra (metadata) space so that they can serialize the requested size of an array (in bytes) into the memory. That will enable higher-kinded functions, implemented on top of Alloc, to take necessary actions such as cleaning up the resources by invoking appropriate number of destructors of non-trivially-destructible types. Otherwise, this would create a burden on end users by having to remember and carry the array size all around the code. This is equivalent to what we find in other standard implementations. For example, new int x[10] is always released without passing the array size: delete[] x; The same holds with this design.

Memory layout representation looks like the following:


| ALLOC-ARR-META | ... DATA ... |

^ ^ | | | | | ptr to be returned to call-site

|

| DATALEN |

\ \ 0 \ alignof(max_align_t) - 1

DATALEN segment encodes the total length of DATA segment, which is the actual allocation size that client code has requested.

DATA segment is a segment that will be returned to the call-site.

Member Typedef Documentation

◆ datalen_t

This is the type we will be using to store the size of an array.

Member Function Documentation

◆ alloc()

template<bool Zero_initialized>
static void * ut::detail::Alloc_arr::alloc ( std::size_t  size)
inlinestaticnoexcept

Sanity check so that we can be sure that our metadata segment can fit the datalen_t.

Sanity check so that we can be sure that the size of our metadata segment is such so that the pointer to DATA segment is always suitably aligned (multiple of alignof(max_align_t). Dynamically allocates storage of given size.

Parameters
[in]sizeSize of storage (in bytes) requested to be allocated.
Returns
Pointer to the allocated storage. nullptr if dynamic storage allocation failed.

◆ datalen()

static datalen_t ut::detail::Alloc_arr::datalen ( void *  ptr)
inlinestatic

Returns the size of an array in bytes.

Parameters
[in]ptrPointer to storage allocated through Alloc_arr::alloc().
Returns
Size of an array in bytes (or number of bytes allocated).

◆ deduce()

static void * ut::detail::Alloc_arr::deduce ( void *  ptr)
inlinestaticprivatenoexcept

Helper function which deduces the original pointer returned by Alloc_arr::alloc() from a pointer which is passed to us by the call-site.

◆ free()

static void ut::detail::Alloc_arr::free ( void *  ptr)
inlinestaticnoexcept

Releases storage dynamically allocated through Alloc_arr::alloc().

Parameters
[in]ptrPointer to storage allocated through Alloc_arr::alloc().

Member Data Documentation

◆ metadata_len

constexpr auto ut::detail::Alloc_arr::metadata_len = alignof(max_align_t)
staticconstexpr

This is how much the metadata (ALLOC-ARR-META) segment will be big.


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