MySQL 8.3.0
Source Code Documentation
temptable::AllocatorState Struct Reference

Shared state between all instances of a given allocator. More...

#include <allocator.h>

Public 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...
 

Detailed Description

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.

Member Data Documentation

◆ current_block

Block temptable::AllocatorState::current_block

Current not-yet-full block to feed allocations from.

◆ number_of_blocks

size_t temptable::AllocatorState::number_of_blocks = 0

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.


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