MySQL 9.1.0
Source Code Documentation
|
Description of a heuristic to determine how much memory to allocate. More...
#include <grow_calculator.h>
Public Types | |
using | Size_t = std::size_t |
using | Result_t = std::pair< bool, Size_t > |
Return type for compute_new_size. More... | |
Public Types inherited from mysql::containers::buffers::Grow_constraint | |
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_calculator () | |
Result_t | compute_new_size (Size_t old_size, Size_t requested_size) const |
Compute the new size. More... | |
Public Member Functions inherited from mysql::containers::buffers::Grow_constraint | |
Grow_constraint ()=default | |
Grow_constraint (const Grow_constraint &other)=default | |
Grow_constraint (Grow_constraint &&other)=default | |
Grow_constraint & | operator= (const Grow_constraint &other)=default |
Grow_constraint & | operator= (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 > | |
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 | default_max_size |
By default, limit memory to 1 GiB. More... | |
static constexpr double | default_grow_factor = 2.0 |
By default, double the size in each allocation. More... | |
static constexpr Size_t | default_grow_increment = 1024 |
By default, allocate at least 1 KiB more in each call. More... | |
static constexpr Size_t | default_block_size = 1024 |
By default, allocate multiples of 1 KiB. More... | |
Static Public Attributes inherited from mysql::containers::buffers::Grow_constraint | |
static constexpr Size_t | machine_max_size = std::numeric_limits<Size_t>::max() |
Maximum allowed value for the application max size. More... | |
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:
using mysql::containers::buffers::Grow_constraint::Result_t = std::pair<bool, Size_t> |
Return type for compute_new_size.
using mysql::containers::buffers::Grow_constraint::Size_t = std::size_t |
mysql::containers::buffers::Grow_calculator::Grow_calculator | ( | ) |
Grow_calculator::Result_t mysql::containers::buffers::Grow_calculator::compute_new_size | ( | Size_t | old_size, |
Size_t | requested_size | ||
) | const |
Compute the new size.
This follows the following rules:
old_size | The existing size. |
requested_size | The total size needed. |
A | pair. The first component is bool and contains the error status: false means success, i.e., the requested size does not exceed the maximum size. It also counts as success if the request is less than the existing size, or if the request is zero. true means error, i.e., the requested size exceeds the maximum size. The second component is the new size. If the first component is true for error, the second component is zero. |
other | value The new size. |
|
staticconstexpr |
By default, allocate multiples of 1 KiB.
|
staticconstexpr |
By default, double the size in each allocation.
|
staticconstexpr |
By default, allocate at least 1 KiB more in each call.
|
staticconstexpr |
By default, limit memory to 1 GiB.