48template <
size_t SIZE = DYN_ARRAY_DATA_SIZE>
95 template <
typename Type>
194 return (block->
end());
216 template <
typename Type>
229 return (block->template push<Type>(
size));
236 void push(
const byte *ptr, uint32_t len) {
246 ::memmove(push<byte *>(n_copied), ptr, n_copied);
257 template <
typename Type>
262 return (
reinterpret_cast<Type>(block->
begin() + pos));
269 template <
typename Type>
273 return (
reinterpret_cast<Type>(block->
begin() + pos));
281 ulint total_size = 0;
284 total_size += block->used();
295 template <
typename Functor>
298 if (!functor(block)) {
309 template <
typename Functor>
313 if (!functor(block)) {
369 for (
auto block :
m_list) {
370 if (pos < block->used()) {
374 pos -= block->used();
378 ut_o(
return nullptr);
424 memcpy(
buf, block->begin(), block->used());
void init()
Initialise the block.
Definition: dyn0buf.h:121
const byte * begin() const
Definition: dyn0buf.h:86
const byte * end() const
Definition: dyn0buf.h:90
ulint m_magic_n
Magic number (DYN_BLOCK_MAGIC_N)
Definition: dyn0buf.h:133
byte * end()
Definition: dyn0buf.h:82
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:147
byte m_data[MAX_DATA_SIZE]
Storage.
Definition: dyn0buf.h:140
static constexpr auto MAX_DATA_SIZE
SIZE - sizeof(m_node) + sizeof(m_used)
Definition: dyn0buf.h:137
void close(const byte *ptr)
Grow the stack.
Definition: dyn0buf.h:107
block_t()
Definition: dyn0buf.h:57
block_node_t m_node
Doubly linked list node.
Definition: dyn0buf.h:143
byte * start()
Gets pointer to the start of data.
Definition: dyn0buf.h:74
ulint used() const
Gets the number of used bytes in a block.
Definition: dyn0buf.h:67
byte * begin()
Definition: dyn0buf.h:78
Type push(uint32_t size)
Definition: dyn0buf.h:96
ulint m_buf_end
If opened then this is the buffer end offset, else 0.
Definition: dyn0buf.h:130
Class that manages dynamic buffers.
Definition: dyn0buf.h:49
dyn_buf_t()
Default constructor.
Definition: dyn0buf.h:156
void push_back(block_t *block)
Add the block to the end of the list.
Definition: dyn0buf.h:341
ulint m_size
Total size used by all blocks.
Definition: dyn0buf.h:405
~dyn_buf_t()
Destructor.
Definition: dyn0buf.h:159
void close(const byte *ptr)
Closes the buffer returned by open.
Definition: dyn0buf.h:200
block_t * back()
Definition: dyn0buf.h:348
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:279
block_t * find(ulint &pos)
Find the block that contains the pos.
Definition: dyn0buf.h:366
byte * open(ulint size)
Makes room on top and returns a pointer to a buffer in it.
Definition: dyn0buf.h:183
typedef UT_LIST_NODE_T(block_t) block_node_t
void erase()
Reset the buffer vector.
Definition: dyn0buf.h:162
static constexpr auto MAX_DATA_SIZE
Definition: dyn0buf.h:153
dyn_buf_t(dyn_buf_t &&)=delete
mem_heap_t * m_heap
Heap to use for memory allocation.
Definition: dyn0buf.h:399
block_t * front()
Definition: dyn0buf.h:323
Type push(uint32_t size)
Makes room on top and returns a pointer to the added element.
Definition: dyn0buf.h:217
Type at(ulint pos)
Returns a pointer to an element in the buffer.
Definition: dyn0buf.h:270
block_t * add_block()
Allocate and add a new block to m_list.
Definition: dyn0buf.h:383
block_t m_first_block
The default block, should always be the first element.
Definition: dyn0buf.h:410
bool has_space(ulint size) const
Definition: dyn0buf.h:352
void push(const byte *ptr, uint32_t len)
Pushes n bytes.
Definition: dyn0buf.h:236
bool for_each_block_in_reverse(Functor &functor) const
Iterate over all the blocks in reverse and call the iterator.
Definition: dyn0buf.h:310
bool is_small() const
Definition: dyn0buf.h:330
dyn_buf_t & operator=(dyn_buf_t &&)=delete
block_list_t m_list
Allocated blocks.
Definition: dyn0buf.h:402
dyn_buf_t & operator=(const dyn_buf_t &)=delete
bool has_space(ulint size)
Definition: dyn0buf.h:358
bool for_each_block(Functor &functor) const
Iterate over each block and call the functor.
Definition: dyn0buf.h:296
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:258
dyn_buf_t< DYN_ARRAY_DATA_SIZE > mtr_buf_t
Definition: dyn0buf.h:413
The dynamically allocated buffer types and constants.
constexpr uint32_t DYN_BLOCK_MAGIC_N
Value of dyn_block_t::magic_n.
Definition: dyn0types.h:40
constexpr uint32_t DYN_BLOCK_FULL_FLAG
Flag for dyn_block_t::used that indicates a full block.
Definition: dyn0types.h:47
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:29
Type
Definition: resource_group_basic_types.h:32
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:301
mtr_buf_t copier
Definition: dyn0buf.h:416
bool operator()(const mtr_buf_t::block_t *block)
Append a block to the redo log buffer.
Definition: dyn0buf.h:422
mtr_buf_t m_buf
The copied buffer.
Definition: dyn0buf.h:418
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:405
#define UT_LOCATION_HERE
Definition: ut0core.h:72
#define ut_error
Abort execution.
Definition: ut0dbg.h:64
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define ut_o(EXPR)
Opposite of ut_d().
Definition: ut0dbg.h:72
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:70
#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:440
#define UT_LIST_GET_FIRST(BASE)
Gets the first node in a two-way list.
Definition: ut0lst.h:445
#define UT_LIST_GET_LAST(BASE)
Gets the last node in a two-way list.
Definition: ut0lst.h:450
#define UT_LIST_GET_PREV(NAME, N)
Gets the previous node in a two-way list.
Definition: ut0lst.h:434
#define UT_LIST_ADD_LAST(LIST, ELEM)
Adds the node as the last element in a two-way linked list.
Definition: ut0lst.h:353