82#define MEM_BLOCK_STANDARD_SIZE \
83 (UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)
91#define MEM_MAX_ALLOC_IN_BUF \
92 ((UNIV_PAGE_SIZE - MEM_BLOCK_HEADER_SIZE - 2 * MEM_NO_MANS_LAND) & \
93 ~(UNIV_MEM_ALIGNMENT - 1))
208 ulint top_sz,
const void *data,
281 ...) MY_ATTRIBUTE((format(printf, 2, 3)));
348#define MEM_BLOCK_HEADER_SIZE \
349 ut_calc_align(sizeof(mem_block_info_t), UNIV_MEM_ALIGNMENT)
372 template <
typename U>
400 new (
reinterpret_cast<void *
>(
p)) T(t);
411 template <
typename U>
422 template <
typename U>
476 if (
get() !=
nullptr) {
484 void *
alloc(
size_t n_bytes)
noexcept {
495 using Ptr = std::unique_ptr<Type, mem_heap_free_functor>;
A C++ wrapper class to the mem_heap_t routines, so that it can be used as an STL allocator.
Definition: mem0mem.h:356
void destroy(pointer p)
Definition: mem0mem.h:403
const T & const_reference
Definition: mem0mem.h:364
size_t size_type
Definition: mem0mem.h:359
~mem_heap_allocator()
Definition: mem0mem.h:378
const T * const_pointer
Definition: mem0mem.h:362
size_type max_size() const
Definition: mem0mem.h:380
mem_heap_t * m_heap
Definition: mem0mem.h:421
mem_heap_allocator(const mem_heap_allocator< U > &other)
Definition: mem0mem.h:373
T value_type
Definition: mem0mem.h:358
mem_heap_allocator(const mem_heap_allocator &other)
Definition: mem0mem.h:368
mem_heap_t * get_mem_heap() const
Get the underlying memory heap object.
Definition: mem0mem.h:418
pointer allocate(size_type n, const_pointer hint=nullptr)
This function returns a pointer to the first element of a newly allocated array large enough to conta...
Definition: mem0mem.h:389
T & reference
Definition: mem0mem.h:363
ptrdiff_t difference_type
Definition: mem0mem.h:360
void deallocate(pointer, size_type)
Definition: mem0mem.h:393
T * pointer
Definition: mem0mem.h:361
const_pointer address(const_reference r) const
Definition: mem0mem.h:397
void construct(pointer p, const_reference t)
Definition: mem0mem.h:399
mem_heap_allocator(mem_heap_t *heap)
Definition: mem0mem.h:366
pointer address(reference r) const
Definition: mem0mem.h:395
const char * p
Definition: ctype-mb.cc:1237
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
Utilities for converting data from the database file to the machine format.
static byte * mem_heap_get_heap_top(mem_heap_t *heap)
Returns a pointer to the heap top.
static bool mem_heap_is_top(mem_heap_t *heap, const void *buf, ulint buf_sz)
Checks if a given chunk of memory is the topmost element stored in the heap.
static void * mem_heap_alloc(mem_heap_t *heap, ulint n)
Allocates n bytes of memory from a memory heap.
static void * mem_heap_replace(mem_heap_t *heap, const void *top, ulint top_sz, ulint new_sz)
Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element.
static void mem_heap_free_top(mem_heap_t *heap, ulint n)
Frees the topmost element in a memory heap.
mem_block_t mem_heap_t
A memory heap is a nonempty linear list of memory blocks.
Definition: mem0mem.h:55
char * mem_heap_printf(mem_heap_t *heap, const char *format,...)
A simple sprintf replacement that dynamically allocates the space for the formatted string from the g...
Definition: memory.cc:195
bool operator!=(const mem_heap_allocator< T > &left, const mem_heap_allocator< T > &right)
Definition: mem0mem.h:433
static void mem_heap_free(mem_heap_t *heap)
Frees the space occupied by a memory heap.
bool operator==(const mem_heap_allocator< T > &left, const mem_heap_allocator< T > &right)
Definition: mem0mem.h:427
char * mem_heap_strcat(mem_heap_t *heap, const char *s1, const char *s2)
Concatenate two strings and return the result, using a memory heap.
Definition: memory.cc:67
constexpr int MEM_NO_MANS_LAND
Definition: mem0mem.h:101
static void * mem_heap_dup_replace(mem_heap_t *heap, const void *top, ulint top_sz, const void *data, ulint data_sz)
Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element and then c...
static size_t mem_heap_get_size(mem_heap_t *heap)
Returns the space in bytes occupied by a memory heap.
constexpr uint64_t MEM_BLOCK_MAGIC_N
Definition: mem0mem.h:344
static uint64_t MEM_SPACE_NEEDED(uint64_t N)
Space needed when allocating for a user a field of length N.
Definition: mem0mem.h:114
static char * mem_heap_strdupl(mem_heap_t *heap, const char *str, ulint len)
Makes a NUL-terminated copy of a nonterminated string, allocated from a memory heap.
static void * mem_heap_zalloc(mem_heap_t *heap, ulint n)
Allocates and zero-fills n bytes of memory from a memory heap.
constexpr uint32_t MEM_HEAP_BTR_SEARCH
this flag can optionally be ORed to MEM_HEAP_BUFFER, in which case heap->free_block is used in some c...
Definition: mem0mem.h:67
const byte MEM_NO_MANS_LAND_BEFORE_BYTE
Definition: mem0mem.h:107
static void * mem_heap_get_top(mem_heap_t *heap, ulint n)
Returns a pointer to the topmost element in a memory heap.
constexpr uint32_t MEM_HEAP_FOR_LOCK_HEAP
Definition: mem0mem.h:74
static mem_heap_t * mem_heap_create(ulint size, ut::Location loc, ulint type=MEM_HEAP_DYNAMIC)
Creates a memory heap.
constexpr uint32_t MEM_HEAP_FOR_BTR_SEARCH
Different type of heaps in terms of which data structure is using them.
Definition: mem0mem.h:70
void * mem_heap_dup(mem_heap_t *heap, const void *data, ulint len)
Duplicate a block of data, allocated from a memory heap.
Definition: memory.cc:57
constexpr uint64_t MEM_FREED_BLOCK_MAGIC_N
Definition: mem0mem.h:345
constexpr uint32_t MEM_BLOCK_START_SIZE
The following start size is used for the first block in the memory heap if the size is not specified,...
Definition: mem0mem.h:80
char * mem_heap_strdup(mem_heap_t *heap, const char *str)
Duplicates a NUL-terminated string, allocated from a memory heap.
Definition: memory.cc:51
void mem_heap_validate(const mem_heap_t *heap)
Validates the contents of a memory heap.
Definition: memory.cc:223
static char * mem_heap_strdup_replace(mem_heap_t *heap, const void *top, ulint top_sz, const char *str)
Allocate a new chunk of memory from a memory heap, possibly discarding the topmost element and then c...
static char * mem_strdup(const char *str)
Duplicates a NUL-terminated string.
const byte MEM_NO_MANS_LAND_AFTER_BYTE
Definition: mem0mem.h:109
constexpr uint32_t MEM_HEAP_FOR_RECV_SYS
Definition: mem0mem.h:73
constexpr uint32_t MEM_HEAP_BUFFER
Definition: mem0mem.h:63
constexpr uint32_t MEM_HEAP_DYNAMIC
Types of allocation for memory heaps: DYNAMIC means allocation from the dynamic memory pool of the C ...
Definition: mem0mem.h:62
static void mem_heap_empty(mem_heap_t *heap)
Empties a memory heap.
static void mem_heap_free_heap_top(mem_heap_t *heap, byte *old_top)
Frees the space in a memory heap exceeding the pointer given.
static void mem_block_validate(const mem_heap_t *heap)
Checks that an object is a memory heap (or a block of it)
constexpr uint32_t MEM_HEAP_FOR_PAGE_HASH
Definition: mem0mem.h:72
static char * mem_strdupl(const char *str, ulint len)
Makes a NUL-terminated copy of a nonterminated string.
std::atomic< Type > N
Definition: ut0counter.h:225
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
Definition: buf0block_hint.cc:30
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2879
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
required string type
Definition: replication_group_member_actions.proto:34
A functor with no state to be used for mem_heap destruction.
Definition: mem0mem.h:491
void operator()(mem_heap_t *heap)
Definition: mem0mem.h:492
Heap wrapper that destroys the heap instance when it goes out of scope.
Definition: mem0mem.h:439
Scoped_heap(size_t n, ut::Location location) noexcept
Constructs heap with a free space of specified size.
Definition: mem0mem.h:448
void * alloc(size_t n_bytes) noexcept
Allocate memory in the heap.
Definition: mem0mem.h:484
~Scoped_heap()=default
Destructor.
Scoped_heap()
Default constructor.
Definition: mem0mem.h:443
Scoped_heap(const Scoped_heap &)=delete
void clear() noexcept
Empty the heap.
Definition: mem0mem.h:475
std::unique_ptr< Type, mem_heap_free_functor > Ptr
Definition: mem0mem.h:495
void reset(Type *p)
Set the pointer to p.
Definition: mem0mem.h:468
Scoped_heap & operator=(Scoped_heap &&)=delete
Ptr m_ptr
Heap to use.
Definition: mem0mem.h:498
Scoped_heap(Scoped_heap &&)=delete
Scoped_heap & operator=(const Scoped_heap &)=delete
void create(size_t n, ut::Location location) noexcept
Create the heap, it must not already be created.
Definition: mem0mem.h:457
Type * get() noexcept
Definition: mem0mem.h:464
The buffer control block structure.
Definition: buf0buf.h:1690
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
ulint start
The value of the struct field 'free' at the creation of the block.
Definition: mem0mem.h:329
ulint len
Physical length of this block in bytes.
Definition: mem0mem.h:319
std::atomic< buf_block_t * > * free_block_ptr
Definition: mem0mem.h:334
ulint total_size
Physical length in bytes of all blocks in the heap.
Definition: mem0mem.h:322
char file_name[16]
File name where the mem heap was created.
Definition: mem0mem.h:307
buf_block_t * buf_block
Definition: mem0mem.h:338
UT_LIST_BASE_NODE_T_EXTERN(mem_block_t, list) base
In the first block of the list this is the base node of the list of blocks; in subsequent blocks this...
ulint line
Line number where the mem heap was created.
Definition: mem0mem.h:309
uint64_t magic_n
Magic number for debugging.
Definition: mem0mem.h:304
ulint type
Type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to MEM_HEAP_BTR_SEARCH.
Definition: mem0mem.h:325
UT_LIST_NODE_T(mem_block_t) list
This contains pointers to next and prev in the list.
ulint free
Offset in bytes of the first free position for user data in the block.
Definition: mem0mem.h:327
Allocators are required to supply the below template class member which enables the possibility of ob...
Definition: mem0mem.h:412
mem_heap_allocator< U > other
Definition: mem0mem.h:413
unsigned long int ulint
Definition: univ.i:406
constexpr uint32_t UNIV_MEM_ALIGNMENT
The following alignment is used in memory allocations in memory heap management to ensure correct ali...
Definition: univ.i:283
Utilities for byte operations.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:57
#define UT_LIST_NODE_GETTER_DEFINITION(t, m)
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member...
Definition: ut0lst.h:270
Random numbers and hashing.
#define ut_calc_align(n, m)
Calculates the smallest multiple of m that is not smaller than n when m is a power of two.
Definition: ut0ut.h:172
int n
Definition: xcom_base.cc:509