MySQL 8.0.39
Source Code Documentation
mysqlns::buffer::Grow_constraint Class Reference

Description of a heuristic to determine how much memory to allocate. More...

#include <grow_constraint.h>

Inheritance diagram for mysqlns::buffer::Grow_constraint:
[legend]

Public Types

using Size_t = std::size_t
 
using Result_t = std::pair< bool, Size_t >
 Return type for compute_new_size. More...
 

Public Member Functions

 Grow_constraint ()=default
 
 Grow_constraint (const Grow_constraint &other)=default
 
 Grow_constraint (Grow_constraint &&other)=default
 
Grow_constraintoperator= (const Grow_constraint &other)=default
 
Grow_constraintoperator= (Grow_constraint &&other)=default
 
virtual ~Grow_constraint ()=default
 
void set_max_size (Size_t max_size)
 Set the maximum size. More...
 
Size_t get_max_size () const
 
void set_grow_factor (double grow_factor)
 Set the grow factor. More...
 
double get_grow_factor () const
 
void set_grow_increment (Size_t grow_increment)
 Set the grow increment. More...
 
Size_t get_grow_increment () const
 
void set_block_size (Size_t block_size)
 Set the block size. More...
 
Size_t get_block_size () const
 
std::string debug_string () const
 In debug mode, return a string that describes the internal structure of this object, to use for debugging. More...
 
template<class T >
combine_with (const T &other) const
 Combine the constraints of this object with another Grow_constraint or Grow_calculator object. More...
 

Static Public Attributes

static constexpr Size_t machine_max_size = std::numeric_limits<Size_t>::max()
 Maximum allowed value for the application max size. More...
 

Private Attributes

Size_t m_max_size {machine_max_size}
 Size must not exceed this number. More...
 
double m_grow_factor {default_grow_factor}
 
Size_t m_grow_increment {default_grow_increment}
 
Size_t m_block_size {default_block_size}
 

Static Private Attributes

static constexpr double default_grow_factor = 1.0
 By default, don't constrain the grow factor. More...
 
static constexpr Size_t default_grow_increment = 0
 By default, don't constrain the grow increment. More...
 
static constexpr Size_t default_block_size = 1
 By default, don't constrain the block size. More...
 

Detailed Description

Description of a heuristic to determine how much memory to allocate.

This may be used in diverse contexts such as growing a memory buffer, or growing a pool of objects.

This encapsulates several common heuristics for growth:

  • The growth rate can be exponential. This is useful for cases such as contiguous memory buffers, where each size increment may copy all the existing data, e.g., using 'realloc'. Or, more generally, any data structure where size growth has a cost that is linear in the total size. In such cases an exponential growth rate ensures that execution time is not quadratic in the number of grow operations.
  • The growth rate can be linear. This is useful for cases such as linked lists, where each size increment is linear in the increment size.
  • There can be an upper bound on the size. This is useful e.g. when there are configurable memory limits.
  • The size can be specified to be a multiple of a given number. This can potentially be useful if there is a way to align allocated objects to page sizes, or similar.

Member Typedef Documentation

◆ Result_t

Return type for compute_new_size.

◆ Size_t

Constructor & Destructor Documentation

◆ Grow_constraint() [1/3]

mysqlns::buffer::Grow_constraint::Grow_constraint ( )
default

◆ Grow_constraint() [2/3]

mysqlns::buffer::Grow_constraint::Grow_constraint ( const Grow_constraint other)
default

◆ Grow_constraint() [3/3]

mysqlns::buffer::Grow_constraint::Grow_constraint ( Grow_constraint &&  other)
default

◆ ~Grow_constraint()

virtual mysqlns::buffer::Grow_constraint::~Grow_constraint ( )
virtualdefault

Member Function Documentation

◆ combine_with()

template<class T >
T mysqlns::buffer::Grow_constraint::combine_with ( const T &  other) const
inline

Combine the constraints of this object with another Grow_constraint or Grow_calculator object.

This will return a new object of the same type as the argument. The returned object will have the smallest max_size among this and other, and the largest grow_factor, grow_increment, and block_size.

◆ debug_string()

std::string mysqlns::buffer::Grow_constraint::debug_string ( ) const
inline

In debug mode, return a string that describes the internal structure of this object, to use for debugging.

◆ get_block_size()

Grow_constraint::Size_t mysqlns::buffer::Grow_constraint::get_block_size ( ) const
Returns
the block size.

◆ get_grow_factor()

double mysqlns::buffer::Grow_constraint::get_grow_factor ( ) const
Returns
the grow factor.

◆ get_grow_increment()

Grow_constraint::Size_t mysqlns::buffer::Grow_constraint::get_grow_increment ( ) const
Returns
the grow increment.

◆ get_max_size()

Grow_constraint::Size_t mysqlns::buffer::Grow_constraint::get_max_size ( ) const
Returns
the maximum size.

◆ operator=() [1/2]

Grow_constraint & mysqlns::buffer::Grow_constraint::operator= ( const Grow_constraint other)
default

◆ operator=() [2/2]

Grow_constraint & mysqlns::buffer::Grow_constraint::operator= ( Grow_constraint &&  other)
default

◆ set_block_size()

void mysqlns::buffer::Grow_constraint::set_block_size ( Size_t  block_size)

Set the block size.

The size should be kept to a multiple of this number.

◆ set_grow_factor()

void mysqlns::buffer::Grow_constraint::set_grow_factor ( double  grow_factor)

Set the grow factor.

Whenever the size needs to increase, it should increase it by at least this factor.

Using a value > 1 ensures that successive calls to reserve() with sizes increasing up to N take amortized linear time in N; a value equal to 1 may result in execution time that is quadratic in N.

◆ set_grow_increment()

void mysqlns::buffer::Grow_constraint::set_grow_increment ( Size_t  grow_increment)

Set the grow increment.

Whenever the size needs to increase, it should increase by at least this amount.

◆ set_max_size()

void mysqlns::buffer::Grow_constraint::set_max_size ( Size_t  max_size)

Set the maximum size.

Whenever more than this is requested, the response should be to fail. This is an inclusive upper bound, so requests for exactly this size are allowed.

Member Data Documentation

◆ default_block_size

constexpr Size_t mysqlns::buffer::Grow_constraint::default_block_size = 1
staticconstexprprivate

By default, don't constrain the block size.

◆ default_grow_factor

constexpr double mysqlns::buffer::Grow_constraint::default_grow_factor = 1.0
staticconstexprprivate

By default, don't constrain the grow factor.

◆ default_grow_increment

constexpr Size_t mysqlns::buffer::Grow_constraint::default_grow_increment = 0
staticconstexprprivate

By default, don't constrain the grow increment.

◆ m_block_size

Size_t mysqlns::buffer::Grow_constraint::m_block_size {default_block_size}
private

◆ m_grow_factor

double mysqlns::buffer::Grow_constraint::m_grow_factor {default_grow_factor}
private

◆ m_grow_increment

Size_t mysqlns::buffer::Grow_constraint::m_grow_increment {default_grow_increment}
private

◆ m_max_size

Size_t mysqlns::buffer::Grow_constraint::m_max_size {machine_max_size}
private

Size must not exceed this number.

◆ machine_max_size

constexpr Size_t mysqlns::buffer::Grow_constraint::machine_max_size = std::numeric_limits<Size_t>::max()
staticconstexpr

Maximum allowed value for the application max size.


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