49template <
size_t SIZE = DYN_ARRAY_DATA_SIZE>
96 template <
typename Type>
195 return (block->
end());
217 template <
typename Type>
230 return (block->template push<Type>(
size));
237 void push(
const byte *ptr, uint32_t len) {
247 ::memmove(push<byte *>(n_copied), ptr, n_copied);
258 template <
typename Type>
263 return (
reinterpret_cast<Type>(block->
begin() + pos));
270 template <
typename Type>
274 return (
reinterpret_cast<Type>(block->
begin() + pos));
282 ulint total_size = 0;
285 total_size += block->used();
296 template <
typename Functor>
299 if (!functor(block)) {
310 template <
typename Functor>
314 if (!functor(block)) {
370 for (
auto block :
m_list) {
371 if (pos < block->used()) {
375 pos -= block->used();
379 ut_o(
return nullptr);
425 memcpy(
buf, block->begin(), block->used());
void init()
Initialise the block.
Definition: dyn0buf.h:122
const byte * begin() const
Definition: dyn0buf.h:87
const byte * end() const
Definition: dyn0buf.h:91
ulint m_magic_n
Magic number (DYN_BLOCK_MAGIC_N)
Definition: dyn0buf.h:134
byte * end()
Definition: dyn0buf.h:83
uint32_t m_used
number of data bytes used in this block; DYN_BLOCK_FULL_FLAG is set when the block becomes full
Definition: dyn0buf.h:148
byte m_data[MAX_DATA_SIZE]
Storage.
Definition: dyn0buf.h:141
static constexpr auto MAX_DATA_SIZE
SIZE - sizeof(m_node) + sizeof(m_used)
Definition: dyn0buf.h:138
void close(const byte *ptr)
Grow the stack.
Definition: dyn0buf.h:108
block_t()
Definition: dyn0buf.h:58
block_node_t m_node
Doubly linked list node.
Definition: dyn0buf.h:144
byte * start()
Gets pointer to the start of data.
Definition: dyn0buf.h:75
ulint used() const
Gets the number of used bytes in a block.
Definition: dyn0buf.h:68
byte * begin()
Definition: dyn0buf.h:79
Type push(uint32_t size)
Definition: dyn0buf.h:97
ulint m_buf_end
If opened then this is the buffer end offset, else 0.
Definition: dyn0buf.h:131
Class that manages dynamic buffers.
Definition: dyn0buf.h:50
dyn_buf_t()
Default constructor.
Definition: dyn0buf.h:157
void push_back(block_t *block)
Add the block to the end of the list.
Definition: dyn0buf.h:342
ulint m_size
Total size used by all blocks.
Definition: dyn0buf.h:406
~dyn_buf_t()
Destructor.
Definition: dyn0buf.h:160
void close(const byte *ptr)
Closes the buffer returned by open.
Definition: dyn0buf.h:201
block_t * back()
Definition: dyn0buf.h:349
typedef UT_LIST_BASE_NODE_T(block_t, m_node) block_list_t
ulint size() const
Returns the size of the total stored data.
Definition: dyn0buf.h:280
block_t * find(ulint &pos)
Find the block that contains the pos.
Definition: dyn0buf.h:367
byte * open(ulint size)
Makes room on top and returns a pointer to a buffer in it.
Definition: dyn0buf.h:184
typedef UT_LIST_NODE_T(block_t) block_node_t
void erase()
Reset the buffer vector.
Definition: dyn0buf.h:163
static constexpr auto MAX_DATA_SIZE
Definition: dyn0buf.h:154
dyn_buf_t(dyn_buf_t &&)=delete
mem_heap_t * m_heap
Heap to use for memory allocation.
Definition: dyn0buf.h:400
block_t * front()
Definition: dyn0buf.h:324
Type push(uint32_t size)
Makes room on top and returns a pointer to the added element.
Definition: dyn0buf.h:218
Type at(ulint pos)
Returns a pointer to an element in the buffer.
Definition: dyn0buf.h:271
block_t * add_block()
Allocate and add a new block to m_list.
Definition: dyn0buf.h:384
block_t m_first_block
The default block, should always be the first element.
Definition: dyn0buf.h:411
bool has_space(ulint size) const
Definition: dyn0buf.h:353
void push(const byte *ptr, uint32_t len)
Pushes n bytes.
Definition: dyn0buf.h:237
bool for_each_block_in_reverse(Functor &functor) const
Iterate over all the blocks in reverse and call the iterator.
Definition: dyn0buf.h:311
bool is_small() const
Definition: dyn0buf.h:331
dyn_buf_t & operator=(dyn_buf_t &&)=delete
block_list_t m_list
Allocated blocks.
Definition: dyn0buf.h:403
dyn_buf_t & operator=(const dyn_buf_t &)=delete
bool has_space(ulint size)
Definition: dyn0buf.h:359
bool for_each_block(Functor &functor) const
Iterate over each block and call the functor.
Definition: dyn0buf.h:297
dyn_buf_t(const dyn_buf_t &)=delete
const Type at(ulint pos) const
Returns a pointer to an element in the buffer.
Definition: dyn0buf.h:259
dyn_buf_t< DYN_ARRAY_DATA_SIZE > mtr_buf_t
Definition: dyn0buf.h:414
The dynamically allocated buffer types and constants.
constexpr uint32_t DYN_BLOCK_MAGIC_N
Value of dyn_block_t::magic_n.
Definition: dyn0types.h:41
constexpr uint32_t DYN_BLOCK_FULL_FLAG
Flag for dyn_block_t::used that indicates a full block.
Definition: dyn0types.h:48
static void * mem_heap_alloc(mem_heap_t *heap, ulint n)
Allocates n bytes of memory from a memory heap.
static void mem_heap_free(mem_heap_t *heap)
Frees the space occupied by a memory heap.
static mem_heap_t * mem_heap_create(ulint size, ut::Location loc, ulint type=MEM_HEAP_DYNAMIC)
Creates a memory heap.
Definition: buf0block_hint.cc:30
Type
Definition: resource_group_basic_types.h:33
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
mtr_buf_t copier
Definition: dyn0buf.h:417
bool operator()(const mtr_buf_t::block_t *block)
Append a block to the redo log buffer.
Definition: dyn0buf.h:423
mtr_buf_t m_buf
The copied buffer.
Definition: dyn0buf.h:419
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:406
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_error
Abort execution.
Definition: ut0dbg.h:101
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_o(EXPR)
Opposite of ut_d().
Definition: ut0dbg.h:109
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:107
#define UT_LIST_GET_LEN(BASE)
Alternative macro to get the number of nodes in a two-way list, i.e., its length.
Definition: ut0lst.h:441
#define UT_LIST_GET_FIRST(BASE)
Gets the first node in a two-way list.
Definition: ut0lst.h:446
#define UT_LIST_GET_LAST(BASE)
Gets the last node in a two-way list.
Definition: ut0lst.h:451
#define UT_LIST_GET_PREV(NAME, N)
Gets the previous node in a two-way list.
Definition: ut0lst.h:435
#define UT_LIST_ADD_LAST(LIST, ELEM)
Adds the node as the last element in a two-way linked list.
Definition: ut0lst.h:354