MySQL 8.4.2
Source Code Documentation
|
Shared state between all instances of a given allocator. More...
#include <allocator.h>
Public Member Functions | |
~AllocatorState () noexcept | |
Destroys the state, deallocate the current_block if it was left empty. More... | |
Block * | get_block_for_new_allocation (size_t n_bytes_requested) |
Gets a Block from which a new allocation of the specified size should be performed. More... | |
void | block_is_not_used_anymore (Block block) noexcept |
Informs the state object of a block that has no data allocated inside of it anymore for garbage collection. More... | |
Private Member Functions | |
void | free_block (Block &block) noexcept |
Frees the specified block and takes care of all accounting. More... | |
Private Attributes | |
Block | current_block |
Current not-yet-full block to feed allocations from. More... | |
size_t | number_of_blocks = 0 |
Number of created blocks so far (by this Allocator object). More... | |
Shared state between all instances of a given allocator.
STL allocators can (since C++11) carry state; however, that state should never be mutable, as the allocator can be copy-constructed and rebound without further notice, so e.g. deallocating memory in one allocator could mean freeing a block that an earlier copy of the allocator still thinks is valid.
Usually, mutable state will be external to the allocator (e.g. Mem_root_allocator will point to a MEM_ROOT, but it won't own the MEM_ROOT); however, TempTable was never written this way, and doesn't have a natural place to stick the allocator state. Thus, we need a kludge where the allocator's state is held in a shared_ptr, owned by all the instances together. This is suboptimal for performance, and also is against the style guide's recommendation to have clear ownership of objects, but at least it avoids the use-after-free.
|
inlinenoexcept |
Destroys the state, deallocate the current_block if it was left empty.
|
inlinenoexcept |
Informs the state object of a block that has no data allocated inside of it anymore for garbage collection.
[in] The empty block to manage and possibly free.
|
inlineprivatenoexcept |
Frees the specified block and takes care of all accounting.
[in] The empty block to free.
|
inline |
Gets a Block from which a new allocation of the specified size should be performed.
It will use the current Block or create a new one if it is too small. [in] Number of bytes that will be allocated from the returned block.
|
private |
Current not-yet-full block to feed allocations from.
|
private |
Number of created blocks so far (by this Allocator object).
We use this number only as a hint as to how big block to create when a new block needs to be created.