MySQL 8.0.39
Source Code Documentation
|
Header is an abstraction with the purpose of holding and maintaining the Block metadata. More...
#include <header.h>
Public Types | |
using | metadata_type = uintptr_t |
Type that we will be using for storing metadata information. More... | |
Public Member Functions | |
Source | memory_source_type () const |
Get the Block Source type (memory where it resides). More... | |
size_t | block_size () const |
Get the Block size. More... | |
size_t | number_of_used_chunks () const |
Get current number of Chunks allocated by the Block. More... | |
size_t | first_pristine_offset () const |
Get current first-pristine-offset. More... | |
Static Public Attributes | |
static constexpr size_t | SIZE = 4 * sizeof(Header::metadata_type) |
Block header (metadata) size. More... | |
Protected Member Functions | |
Header () noexcept | |
Default constructor which creates an empty Header. More... | |
Header (uint8_t *block_memory, Source block_memory_type, size_t block_size) noexcept | |
Constructor which initializes the Header metadata when constructing fresh Blocks. More... | |
Header (uint8_t *block_memory) noexcept | |
Constructor which initializes the Header metadata from already existing Blocks in memory (e.g. More... | |
uint8_t * | next_available_slot () const |
Enable Block to get the next available slot that it can use for next Chunk allocation. More... | |
uint8_t * | block_address () const |
Enable Block to get its memory address. More... | |
size_t | increment_number_of_used_chunks (size_t chunk_size) |
Enable Block to increment the reference-count when (logically) allocating new Chunks. More... | |
size_t | decrement_number_of_used_chunks (size_t chunk_size, bool rightmost_chunk) |
Enable Block to decrement the reference-count when (logically) deallocating existing Chunks. More... | |
void | reset () |
Enable Block to reset the Header metadata upon Block destruction. More... | |
Static Private Member Functions | |
static Header::metadata_type * | block_memory_type_ptr (uint8_t *block) |
Deduce a pointer to the memory type of given Block. More... | |
static Header::metadata_type * | block_size_ptr (uint8_t *block) |
Deduce a pointer to the size of given Block. More... | |
static Header::metadata_type * | block_number_of_used_chunks_ptr (uint8_t *block) |
Deduce a pointer to the number of used/allocated Chunks of given Block. More... | |
static Header::metadata_type * | block_first_pristine_offset_ptr (uint8_t *block) |
Deduce a pointer to the first-pristine-offset of given Block. More... | |
Private Attributes | |
uint8_t * | m_offset |
A pointer to the allocated Block memory which is used to deduce all of the other remaining metadata structure. More... | |
Header is an abstraction with the purpose of holding and maintaining the Block metadata.
Block metadata has the following structure:
That implies Chunks occupy the following range in memory:
1st byte of [0, N) region is an actual pointer returned by memory allocation functions (e.g. malloc/new/mmap/etc.). Given that we are working with contiguous memory, storing that byte (offset) is just enough to be able to build-up and deduce Header metadata structure.
Part of the Header contract is to have its metadata properly aligned in memory. Given that this memory is provided by the Block, Header implements debug-asserts to actually check if this condition has been met. If that was not the case, then accessing unaligned memory addresses would:
In order to maintain proper memory alignment of the whole metadata structure, CPU word-size data-type is used. Our N is defined by the size of that type (Header::metadata_type).
using temptable::Header::metadata_type = uintptr_t |
Type that we will be using for storing metadata information.
|
inlineprotectednoexcept |
Default constructor which creates an empty Header.
|
inlineprotectednoexcept |
Constructor which initializes the Header metadata when constructing fresh Blocks.
[in] Pointer to the allocated Block memory. [in] Source where Block has allocated actual memory from. [in] Size of the Block
|
inlineexplicitprotectednoexcept |
Constructor which initializes the Header metadata from already existing Blocks in memory (e.g.
ones that are deduced from Chunks).
[in] Pointer to the existing Block.
|
inlineprotected |
Enable Block to get its memory address.
|
inlinestaticprivate |
Deduce a pointer to the first-pristine-offset of given Block.
|
inlinestaticprivate |
Deduce a pointer to the memory type of given Block.
|
inlinestaticprivate |
Deduce a pointer to the number of used/allocated Chunks of given Block.
|
inline |
Get the Block size.
|
inlinestaticprivate |
Deduce a pointer to the size of given Block.
|
inlineprotected |
Enable Block to decrement the reference-count when (logically) deallocating existing Chunks.
[in] Size of the Chunk. [in] Boolean which denotes if Chunk being deallocated is the last (rightmost) one.
|
inline |
Get current first-pristine-offset.
This offset is always relative to the block start (block-address).
|
inlineprotected |
Enable Block to increment the reference-count when (logically) allocating new Chunks.
[in] Size of the Chunk.
|
inline |
Get the Block Source type (memory where it resides).
|
inlineprotected |
Enable Block to get the next available slot that it can use for next Chunk allocation.
|
inline |
Get current number of Chunks allocated by the Block.
|
inlineprotected |
Enable Block to reset the Header metadata upon Block destruction.
|
private |
A pointer to the allocated Block memory which is used to deduce all of the other remaining metadata structure.
|
staticconstexpr |
Block header (metadata) size.
As described, there are 4 elements.