MySQL 8.4.2
Source Code Documentation
|
Chunk is an abstraction with the purpose of representing a smallest logical memory-unit within the Block. More...
#include <chunk.h>
Public Types | |
using | metadata_type = uintptr_t |
Type that we will be using for storing metadata information. More... | |
Public Member Functions | |
Chunk (uint8_t *offset, size_t new_offset) noexcept | |
Constructor which Block will use to create a fresh Chunk object at the given memory-offset. More... | |
Chunk (void *data) noexcept | |
Constructor which Block will use to re-create Chunk object from user-provided pointer which points to the data section of already existing Chunk in memory. More... | |
uint8_t * | block () const |
Deduce the memory-address of belonging Block. More... | |
size_t | offset () const |
Get the Chunk offset relative to the start of belonging Block. More... | |
uint8_t * | data () const |
Get the pointer to the data section which will be provided to the end-user. More... | |
Static Public Member Functions | |
static size_t | size_hint (size_t n_bytes) |
For given size, how much memory will be occupied by the Chunk. More... | |
Static Public Attributes | |
static constexpr size_t | METADATA_SIZE = sizeof(Chunk::metadata_type) |
Chunk metadata size. More... | |
Static Private Member Functions | |
static Chunk::metadata_type * | chunk_offset_ptr (uint8_t *chunk) |
Deduce a pointer to the offset of given Chunk. More... | |
static uint8_t * | chunk_data_ptr (uint8_t *chunk) |
Deduce a pointer to the data payload of given Chunk. More... | |
Private Attributes | |
uint8_t * | m_offset |
A pointer to the actual memory-location where Chunk is located at. More... | |
Chunk is an abstraction with the purpose of representing a smallest logical memory-unit within the Block.
Block allocations and deallocations are served in Chunks.
Chunk structure is:
As it can be seen, Chunk doesn't hold almost any information (e.g. its size) but merely an offset relative to the Block address it belongs to. That's what it enables Block to implement allocations and deallocations in constant-time.
Part of the Chunk contract is to have its metadata properly aligned in memory. Given that this memory is provided by the Block, Chunk implements debug-asserts to actually check if this condition has been met. If that was not the case, then accessing unaligned memory addresses would:
OTOH, checking if Chunk user data is properly aligned is not possible from this context because actual data-type is not known to a Chunk. This check however shall be implemented in the context where the type is known (e.g. Allocator)
using temptable::Chunk::metadata_type = uintptr_t |
Type that we will be using for storing metadata information.
|
inlinenoexcept |
Constructor which Block will use to create a fresh Chunk object at the given memory-offset.
[in] Pointer to the actual memory-location where Chunk will be located at. [in] Offset relative to address of a Block that is creating this Chunk.
|
inlineexplicitnoexcept |
Constructor which Block will use to re-create Chunk object from user-provided pointer which points to the data section of already existing Chunk in memory.
This pointer is returned to the user upon every Chunk allocation.
[in] Pointer to the data section of existing Chunk.
|
inline |
Deduce the memory-address of belonging Block.
|
inlinestaticprivate |
Deduce a pointer to the data payload of given Chunk.
[in] Pointer to the first memory location (m_offset) which represents the chunk.
|
inlinestaticprivate |
Deduce a pointer to the offset of given Chunk.
[in] Pointer to the first memory location (m_offset) which represents the chunk.
|
inline |
Get the pointer to the data section which will be provided to the end-user.
|
inline |
Get the Chunk offset relative to the start of belonging Block.
|
inlinestatic |
For given size, how much memory will be occupied by the Chunk.
This calculation takes into account both the metadata and data payload.
[in] Data payload size in bytes.
|
private |
A pointer to the actual memory-location where Chunk is located at.
|
staticconstexpr |
Chunk metadata size.
As described, there is only 1 element.