MySQL 8.0.32
Source Code Documentation
dyn_buf_t< SIZE > Class Template Reference

Class that manages dynamic buffers. More...

#include <dyn0buf.h>

Classes

class  block_t
 

Public Member Functions

typedef UT_LIST_NODE_T (block_t) block_node_t
 
typedef UT_LIST_BASE_NODE_T (block_t, m_node) block_list_t
 
 dyn_buf_t ()
 Default constructor. More...
 
 ~dyn_buf_t ()
 Destructor. More...
 
void erase ()
 Reset the buffer vector. More...
 
byteopen (ulint size)
 Makes room on top and returns a pointer to a buffer in it. More...
 
void close (const byte *ptr)
 Closes the buffer returned by open. More...
 
template<typename Type >
Type push (uint32_t size)
 Makes room on top and returns a pointer to the added element. More...
 
void push (const byte *ptr, uint32_t len)
 Pushes n bytes. More...
 
template<typename Type >
const Type at (ulint pos) const
 Returns a pointer to an element in the buffer. More...
 
template<typename Type >
Type at (ulint pos)
 Returns a pointer to an element in the buffer. More...
 
ulint size () const
 Returns the size of the total stored data. More...
 
template<typename Functor >
bool for_each_block (Functor &functor) const
 Iterate over each block and call the functor. More...
 
template<typename Functor >
bool for_each_block_in_reverse (Functor &functor) const
 Iterate over all the blocks in reverse and call the iterator. More...
 
block_tfront ()
 
bool is_small () const
 

Static Public Attributes

static constexpr auto MAX_DATA_SIZE = block_t::MAX_DATA_SIZE
 

Private Member Functions

 dyn_buf_t (dyn_buf_t &&)=delete
 
 dyn_buf_t (const dyn_buf_t &)=delete
 
dyn_buf_toperator= (dyn_buf_t &&)=delete
 
dyn_buf_toperator= (const dyn_buf_t &)=delete
 
void push_back (block_t *block)
 Add the block to the end of the list. More...
 
block_tback ()
 
bool has_space (ulint size) const
 
bool has_space (ulint size)
 
block_tfind (ulint &pos)
 Find the block that contains the pos. More...
 
block_tadd_block ()
 Allocate and add a new block to m_list. More...
 

Private Attributes

mem_heap_tm_heap
 Heap to use for memory allocation. More...
 
block_list_t m_list
 Allocated blocks. More...
 
ulint m_size
 Total size used by all blocks. More...
 
block_t m_first_block
 The default block, should always be the first element. More...
 

Detailed Description

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
class dyn_buf_t< SIZE >

Class that manages dynamic buffers.

It uses a UT_LIST of dyn_buf_t::block_t instances. We don't use STL containers in order to avoid the overhead of heap calls. Using a custom memory allocator doesn't solve the problem either because we have to get the memory from somewhere. We can't use the block_t::m_data as the backend for the custom allocator because we would like the data in the blocks to be contiguous.

Constructor & Destructor Documentation

◆ dyn_buf_t() [1/3]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
dyn_buf_t< SIZE >::dyn_buf_t ( )
inline

Default constructor.

◆ ~dyn_buf_t()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
dyn_buf_t< SIZE >::~dyn_buf_t ( )
inline

Destructor.

◆ dyn_buf_t() [2/3]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
dyn_buf_t< SIZE >::dyn_buf_t ( dyn_buf_t< SIZE > &&  )
privatedelete

◆ dyn_buf_t() [3/3]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
dyn_buf_t< SIZE >::dyn_buf_t ( const dyn_buf_t< SIZE > &  )
privatedelete

Member Function Documentation

◆ add_block()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
block_t * dyn_buf_t< SIZE >::add_block ( )
inlineprivate

Allocate and add a new block to m_list.

◆ at() [1/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
template<typename Type >
Type dyn_buf_t< SIZE >::at ( ulint  pos)
inline

Returns a pointer to an element in the buffer.

non const version.

Parameters
posposition of element in bytes from start
Returns
pointer to element

◆ at() [2/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
template<typename Type >
const Type dyn_buf_t< SIZE >::at ( ulint  pos) const
inline

Returns a pointer to an element in the buffer.

const version.

Parameters
posposition of element in bytes from start
Returns
pointer to element

◆ back()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
block_t * dyn_buf_t< SIZE >::back ( )
inlineprivate
Returns
the last block in the list

◆ close()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
void dyn_buf_t< SIZE >::close ( const byte ptr)
inline

Closes the buffer returned by open.

Parameters
ptrend of used space

◆ erase()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
void dyn_buf_t< SIZE >::erase ( )
inline

Reset the buffer vector.

◆ find()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
block_t * dyn_buf_t< SIZE >::find ( ulint pos)
inlineprivate

Find the block that contains the pos.

Parameters
posabsolute offset, it is updated to make it relative to the block
Returns
the block containing the pos.

◆ for_each_block()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
template<typename Functor >
bool dyn_buf_t< SIZE >::for_each_block ( Functor &  functor) const
inline

Iterate over each block and call the functor.

Returns
false if iteration was terminated.

◆ for_each_block_in_reverse()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
template<typename Functor >
bool dyn_buf_t< SIZE >::for_each_block_in_reverse ( Functor &  functor) const
inline

Iterate over all the blocks in reverse and call the iterator.

Returns
false if iteration was terminated.

◆ front()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
block_t * dyn_buf_t< SIZE >::front ( )
inline
Returns
the first block

◆ has_space() [1/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
bool dyn_buf_t< SIZE >::has_space ( ulint  size)
inlineprivate

◆ has_space() [2/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
bool dyn_buf_t< SIZE >::has_space ( ulint  size) const
inlineprivate

◆ is_small()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
bool dyn_buf_t< SIZE >::is_small ( ) const
inline
Returns
true if m_first_block block was not filled fully

◆ open()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
byte * dyn_buf_t< SIZE >::open ( ulint  size)
inline

Makes room on top and returns a pointer to a buffer in it.

After copying the elements, the caller must close the buffer using close().

Parameters
sizein bytes of the buffer; MUST be <= MAX_DATA_SIZE!
Returns
pointer to the buffer

◆ operator=() [1/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
dyn_buf_t & dyn_buf_t< SIZE >::operator= ( const dyn_buf_t< SIZE > &  )
privatedelete

◆ operator=() [2/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
dyn_buf_t & dyn_buf_t< SIZE >::operator= ( dyn_buf_t< SIZE > &&  )
privatedelete

◆ push() [1/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
void dyn_buf_t< SIZE >::push ( const byte ptr,
uint32_t  len 
)
inline

Pushes n bytes.

Parameters
ptrstring to write
lenstring length

◆ push() [2/2]

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
template<typename Type >
Type dyn_buf_t< SIZE >::push ( uint32_t  size)
inline

Makes room on top and returns a pointer to the added element.

The caller must copy the element to the pointer returned.

Parameters
sizein bytes of the element
Returns
pointer to the element

◆ push_back()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
void dyn_buf_t< SIZE >::push_back ( block_t block)
inlineprivate

Add the block to the end of the list.

◆ size()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
ulint dyn_buf_t< SIZE >::size ( ) const
inline

Returns the size of the total stored data.

Returns
data size in bytes

◆ UT_LIST_BASE_NODE_T()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
typedef dyn_buf_t< SIZE >::UT_LIST_BASE_NODE_T ( block_t  ,
m_node   
)

◆ UT_LIST_NODE_T()

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
typedef dyn_buf_t< SIZE >::UT_LIST_NODE_T ( block_t  )

Member Data Documentation

◆ m_first_block

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
block_t dyn_buf_t< SIZE >::m_first_block
private

The default block, should always be the first element.

This is for backwards compatibility and to avoid an extra heap allocation for small REDO log records

◆ m_heap

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
mem_heap_t* dyn_buf_t< SIZE >::m_heap
private

Heap to use for memory allocation.

◆ m_list

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
block_list_t dyn_buf_t< SIZE >::m_list
private

Allocated blocks.

◆ m_size

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
ulint dyn_buf_t< SIZE >::m_size
private

Total size used by all blocks.

◆ MAX_DATA_SIZE

template<size_t SIZE = DYN_ARRAY_DATA_SIZE>
constexpr auto dyn_buf_t< SIZE >::MAX_DATA_SIZE = block_t::MAX_DATA_SIZE
staticconstexpr

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