MySQL 8.0.31
Source Code Documentation
mem0mem.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/mem0mem.h
28 The memory management
29
30 Created 6/9/1994 Heikki Tuuri
31 *******************************************************/
32
33#ifndef mem0mem_h
34#define mem0mem_h
35
36#include "mach0data.h"
37#include "ut0byte.h"
38#include "ut0mem.h"
39#include "ut0rnd.h"
40
41#include <limits.h>
42
43#include <functional>
44#include <memory>
45#include <type_traits>
46
47/* -------------------- MEMORY HEAPS ----------------------------- */
48
49/** A block of a memory heap consists of the info structure
50followed by an area of memory */
52
53/** A memory heap is a nonempty linear list of memory blocks */
55
56/** Types of allocation for memory heaps: DYNAMIC means allocation from the
57dynamic memory pool of the C compiler, BUFFER means allocation from the
58buffer pool; the latter method is used for very big heaps */
59
60/** the most common type */
61constexpr uint32_t MEM_HEAP_DYNAMIC = 0;
62constexpr uint32_t MEM_HEAP_BUFFER = 1;
63/** this flag can optionally be ORed to MEM_HEAP_BUFFER, in which case
64 heap->free_block is used in some cases for memory allocations, and if it's
65 NULL, the memory allocation functions can return NULL. */
66constexpr uint32_t MEM_HEAP_BTR_SEARCH = 2;
67
68/** Different type of heaps in terms of which data structure is using them */
69constexpr uint32_t MEM_HEAP_FOR_BTR_SEARCH =
74
75/** The following start size is used for the first block in the memory heap if
76the size is not specified, i.e., 0 is given as the parameter in the call of
77create. The standard size is the maximum (payload) size of the blocks used for
78allocations of small buffers. */
79constexpr uint32_t MEM_BLOCK_START_SIZE = 64;
80
81#define MEM_BLOCK_STANDARD_SIZE \
82 (UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)
83
84/** If a memory heap is allowed to grow into the buffer pool, the following
85is the maximum size for a single allocated buffer
86(from UNIV_PAGE_SIZE we subtract MEM_BLOCK_HEADER_SIZE and 2*MEM_NO_MANS_LAND
87since it's something we always need to put. Since in MEM_SPACE_NEEDED we round
88n to the next multiple of UNIV_MEM_ALINGMENT, we need to cut from the rest the
89part that cannot be divided by UNIV_MEM_ALINGMENT): */
90#define MEM_MAX_ALLOC_IN_BUF \
91 ((UNIV_PAGE_SIZE - MEM_BLOCK_HEADER_SIZE - 2 * MEM_NO_MANS_LAND) & \
92 ~(UNIV_MEM_ALIGNMENT - 1))
93
94/* Before and after any allocated object we will put MEM_NO_MANS_LAND bytes of
95some data (different before and after) which is supposed not to be modified by
96anyone. This way it would be much easier to determine whether anyone was
97writing on not his memory, especially that Valgrind can assure there was no
98reads or writes to this memory. */
99#ifdef UNIV_DEBUG
100constexpr int MEM_NO_MANS_LAND = 16;
101#else
102constexpr int MEM_NO_MANS_LAND = 0;
103#endif
104
105/* Byte that we would put before allocated object MEM_NO_MANS_LAND times.*/
107/* Byte that we would put after allocated object MEM_NO_MANS_LAND times.*/
109
110/** Space needed when allocating for a user a field of length N.
111The space is allocated only in multiples of UNIV_MEM_ALIGNMENT. In debug mode
112contains two areas of no mans lands before and after the buffer requested. */
113static inline uint64_t MEM_SPACE_NEEDED(uint64_t N) {
115}
116
117/** Creates a memory heap.
118A single user buffer of 'size' will fit in the block.
1190 creates a default size block.
120@param[in] size Desired start block size.
121@param[in] loc Location where created
122@param[in] type Heap type
123@return own: memory heap, NULL if did not succeed (only possible for
124MEM_HEAP_BTR_SEARCH type heaps) */
127
128/** Frees the space occupied by a memory heap.
129@param[in] heap Heap to be freed */
130static inline void mem_heap_free(mem_heap_t *heap);
131
132/** Allocates and zero-fills n bytes of memory from a memory heap.
133@param[in] heap memory heap
134@param[in] n number of bytes; if the heap is allowed to grow into
135the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
136@return allocated, zero-filled storage */
137static inline void *mem_heap_zalloc(mem_heap_t *heap, ulint n);
138
139/** Allocates n bytes of memory from a memory heap.
140@param[in] heap memory heap
141@param[in] n number of bytes; if the heap is allowed to grow into
142the buffer pool, this must be <= MEM_MAX_ALLOC_IN_BUF
143@return allocated storage, NULL if did not succeed (only possible for
144MEM_HEAP_BTR_SEARCH type heaps) */
145static inline void *mem_heap_alloc(mem_heap_t *heap, ulint n);
146
147/** Returns a pointer to the heap top.
148@param[in] heap memory heap
149@return pointer to the heap top */
150static inline byte *mem_heap_get_heap_top(mem_heap_t *heap);
151
152/** Frees the space in a memory heap exceeding the pointer given.
153The pointer must have been acquired from mem_heap_get_heap_top.
154The first memory block of the heap is not freed.
155@param[in] heap heap from which to free
156@param[in] old_top pointer to old top of heap */
157static inline void mem_heap_free_heap_top(mem_heap_t *heap, byte *old_top);
158
159/** Empties a memory heap.
160The first memory block of the heap is not freed.
161@param[in] heap heap to empty */
162static inline void mem_heap_empty(mem_heap_t *heap);
163
164/** Returns a pointer to the topmost element in a memory heap.
165The size of the element must be given.
166@param[in] heap memory heap
167@param[in] n size of the topmost element
168@return pointer to the topmost element */
169static inline void *mem_heap_get_top(mem_heap_t *heap, ulint n);
170
171/** Checks if a given chunk of memory is the topmost element stored in the
172heap. If this is the case, then calling mem_heap_free_top() would free
173that element from the heap.
174@param[in] heap memory heap
175@param[in] buf presumed topmost element
176@param[in] buf_sz size of buf in bytes
177@return true if topmost */
178[[nodiscard]] static inline bool mem_heap_is_top(mem_heap_t *heap,
179 const void *buf, ulint buf_sz);
180
181/** Allocate a new chunk of memory from a memory heap, possibly discarding the
182topmost element. If the memory chunk specified with (top, top_sz) is the
183topmost element, then it will be discarded, otherwise it will be left untouched
184and this function will be equivallent to mem_heap_alloc().
185@param[in,out] heap memory heap
186@param[in] top chunk to discard if possible
187@param[in] top_sz size of top in bytes
188@param[in] new_sz desired size of the new chunk
189@return allocated storage, NULL if did not succeed (only possible for
190MEM_HEAP_BTR_SEARCH type heaps) */
191static inline void *mem_heap_replace(mem_heap_t *heap, const void *top,
192 ulint top_sz, ulint new_sz);
193
194/** Allocate a new chunk of memory from a memory heap, possibly discarding the
195topmost element and then copy the specified data to it. If the memory chunk
196specified with (top, top_sz) is the topmost element, then it will be discarded,
197otherwise it will be left untouched and this function will be equivalent to
198mem_heap_dup().
199@param[in,out] heap memory heap
200@param[in] top chunk to discard if possible
201@param[in] top_sz size of top in bytes
202@param[in] data new data to duplicate
203@param[in] data_sz size of data in bytes
204@return allocated storage, NULL if did not succeed (only possible for
205MEM_HEAP_BTR_SEARCH type heaps) */
206static inline void *mem_heap_dup_replace(mem_heap_t *heap, const void *top,
207 ulint top_sz, const void *data,
208 ulint data_sz);
209
210/** Allocate a new chunk of memory from a memory heap, possibly discarding the
211topmost element and then copy the specified string to it. If the memory chunk
212specified with (top, top_sz) is the topmost element, then it will be discarded,
213otherwise it will be left untouched and this function will be equivalent to
214mem_heap_strdup().
215@param[in,out] heap memory heap
216@param[in] top chunk to discard if possible
217@param[in] top_sz size of top in bytes
218@param[in] str new data to duplicate
219@return allocated string, NULL if did not succeed (only possible for
220MEM_HEAP_BTR_SEARCH type heaps) */
221static inline char *mem_heap_strdup_replace(mem_heap_t *heap, const void *top,
222 ulint top_sz, const char *str);
223
224/** Frees the topmost element in a memory heap.
225@param[in] heap memory heap
226@param[in] n size of the topmost element
227The size of the element must be given. */
228static inline void mem_heap_free_top(mem_heap_t *heap, ulint n);
229
230/** Returns the space in bytes occupied by a memory heap. */
231static inline ulint mem_heap_get_size(mem_heap_t *heap); /*!< in: heap */
232
233/** Duplicates a NUL-terminated string.
234@param[in] str string to be copied
235@return own: a copy of the string, must be deallocated with ut_free */
236static inline char *mem_strdup(const char *str);
237
238/** Makes a NUL-terminated copy of a nonterminated string.
239@param[in] str string to be copied
240@param[in] len length of str, in bytes
241@return own: a copy of the string, must be deallocated with ut_free */
242static inline char *mem_strdupl(const char *str, ulint len);
243
244/** Duplicates a NUL-terminated string, allocated from a memory heap.
245@param[in] heap memory heap where string is allocated
246@param[in] str string to be copied
247@return own: a copy of the string */
248char *mem_heap_strdup(mem_heap_t *heap, const char *str);
249
250/** Makes a NUL-terminated copy of a nonterminated string, allocated from a
251memory heap.
252@param[in] heap memory heap where string is allocated
253@param[in] str string to be copied
254@param[in] len length of str, in bytes
255@return own: a copy of the string */
256static inline char *mem_heap_strdupl(mem_heap_t *heap, const char *str,
257 ulint len);
258
259/** Concatenate two strings and return the result, using a memory heap.
260 @return own: the result */
261char *mem_heap_strcat(
262 mem_heap_t *heap, /*!< in: memory heap where string is allocated */
263 const char *s1, /*!< in: string 1 */
264 const char *s2); /*!< in: string 2 */
265
266/** Duplicate a block of data, allocated from a memory heap.
267 @return own: a copy of the data */
268void *mem_heap_dup(
269 mem_heap_t *heap, /*!< in: memory heap where copy is allocated */
270 const void *data, /*!< in: data to be copied */
271 ulint len); /*!< in: length of data, in bytes */
272
273/** A simple sprintf replacement that dynamically allocates the space for the
274 formatted string from the given heap. This supports a very limited set of
275 the printf syntax: types 's' and 'u' and length modifier 'l' (which is
276 required for the 'u' type).
277 @return heap-allocated formatted string */
278char *mem_heap_printf(mem_heap_t *heap, /*!< in: memory heap */
279 const char *format, /*!< in: format string */
280 ...) MY_ATTRIBUTE((format(printf, 2, 3)));
281
282/** Checks that an object is a memory heap (or a block of it)
283@param[in] heap Memory heap to check */
284static inline void mem_block_validate(const mem_heap_t *heap);
285
286#ifdef UNIV_DEBUG
287
288/** Validates the contents of a memory heap.
289Checks a memory heap for consistency, prints the contents if any error
290is detected. A fatal error is logged if an error is detected.
291@param[in] heap Memory heap to validate. */
292void mem_heap_validate(const mem_heap_t *heap);
293
294#endif /* UNIV_DEBUG */
295
296/*#######################################################################*/
297
298/** The info structure stored at the beginning of a heap block */
300 /** magic number for debugging */
301 uint64_t magic_n;
302#ifdef UNIV_DEBUG
303 /** file name where the mem heap was created */
304 char file_name[16];
305 /** line number where the mem heap was created */
307#endif /* UNIV_DEBUG */
308 /** This contains pointers to next and prev in the list. The first block
309 allocated to the heap is also the first block in this list,
310 though it also contains the base node of the list.*/
312 /** In the first block of the list this is the base node of the list of
313 blocks; in subsequent blocks this is undefined */
315 /** physical length of this block in bytes */
317 /** physical length in bytes of all blocks in the heap. This is defined only
318 in the base node and is set to ULINT_UNDEFINED in others. */
320 /** type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to
321 MEM_HEAP_BTR_SEARCH */
323 /** offset in bytes of the first free position for user data in the block */
325 /** the value of the struct field 'free' at the creation of the block */
327 /** if the MEM_HEAP_BTR_SEARCH bit is set in type, and this is the heap root,
328 this can contain an allocated buffer frame, which can be appended as a free
329 block to the heap, if we need more space; otherwise, this is NULL */
330 std::atomic<void *> free_block;
331 /** if this block has been allocated from the buffer pool, this contains the
332 buf_block_t handle; otherwise, this is NULL */
334};
335/* We use the UT_LIST_BASE_NODE_T_EXTERN instead of simpler UT_LIST_BASE_NODE_T
336because DevStudio12.6 initializes the pointer-to-member offset to 0 otherwise.*/
338
339constexpr uint64_t MEM_BLOCK_MAGIC_N = 0x445566778899AABB;
340constexpr uint64_t MEM_FREED_BLOCK_MAGIC_N = 0xBBAA998877665544;
341
342/* Header size for a memory heap block */
343#define MEM_BLOCK_HEADER_SIZE \
344 ut_calc_align(sizeof(mem_block_info_t), UNIV_MEM_ALIGNMENT)
345
346#include "mem0mem.ic"
347
348/** A C++ wrapper class to the mem_heap_t routines, so that it can be used
349as an STL allocator */
350template <typename T>
352 public:
353 typedef T value_type;
354 typedef size_t size_type;
355 typedef ptrdiff_t difference_type;
356 typedef T *pointer;
357 typedef const T *const_pointer;
358 typedef T &reference;
359 typedef const T &const_reference;
360
362
364 // Do nothing
365 }
366
367 template <typename U>
369 : m_heap(other.m_heap) {
370 // Do nothing
371 }
372
374
375 size_type max_size() const { return (ULONG_MAX / sizeof(T)); }
376
377 /** This function returns a pointer to the first element of a newly
378 allocated array large enough to contain n objects of type T; only the
379 memory is allocated, and the objects are not constructed. Moreover,
380 an optional pointer argument (that points to an object already
381 allocated by mem_heap_allocator) can be used as a hint to the
382 implementation about where the new memory should be allocated in
383 order to improve locality. */
384 pointer allocate(size_type n, const_pointer hint [[maybe_unused]] = nullptr) {
385 return (reinterpret_cast<pointer>(mem_heap_alloc(m_heap, n * sizeof(T))));
386 }
387
389
390 pointer address(reference r) const { return (&r); }
391
393
395 new (reinterpret_cast<void *>(p)) T(t);
396 }
397
398 void destroy(pointer p) { (reinterpret_cast<T *>(p))->~T(); }
399
400 /** Allocators are required to supply the below template class member
401 which enables the possibility of obtaining a related allocator,
402 parametrized in terms of a different type. For example, given an
403 allocator type IntAllocator for objects of type int, a related
404 allocator type for objects of type long could be obtained using
405 IntAllocator::rebind<long>::other */
406 template <typename U>
407 struct rebind {
409 };
410
411 /** Get the underlying memory heap object.
412 @return the underlying memory heap object. */
413 mem_heap_t *get_mem_heap() const { return (m_heap); }
414
415 private:
417 template <typename U>
418 friend class mem_heap_allocator;
419};
420
421template <class T>
423 const mem_heap_allocator<T> &right) {
424 return (left.get_mem_heap() == right.get_mem_heap());
425}
426
427template <class T>
429 const mem_heap_allocator<T> &right) {
430 return (left.get_mem_heap() != right.get_mem_heap());
431}
432
433/** Heap wrapper that destroys the heap instance when it goes out of scope. */
436
437 /** Default constructor. */
439
440 /** Constructs heap with a free space of specified size.
441 @param[in] n Initial size of the heap to allocate.
442 @param[in] location Location from where called. */
443 Scoped_heap(size_t n, ut::Location location) noexcept
444 : m_ptr(mem_heap_create(n, location, MEM_HEAP_DYNAMIC)) {}
445
446 /** Destructor. */
447 ~Scoped_heap() = default;
448
449 /** Create the heap, it must not already be created.
450 @param[in] n Initial size of the heap to allocate.
451 @param[in] location Location from where called. */
452 void create(size_t n, ut::Location location) noexcept {
453 ut_a(get() == nullptr);
454 auto ptr = mem_heap_create(n, location, MEM_HEAP_DYNAMIC);
455 reset(ptr);
456 }
457
458 /** @return the heap pointer. */
459 Type *get() noexcept { return m_ptr.get(); }
460
461 /** Set the pointer to p.
462 @param[in] p New pointer value. */
463 void reset(Type *p) {
464 if (get() != p) {
465 m_ptr.reset(p);
466 }
467 }
468
469 /** Empty the heap. */
470 void clear() noexcept {
471 if (get() != nullptr) {
473 }
474 }
475
476 /** Allocate memory in the heap.
477 @param[in] n_bytes Number of bytes to allocate.
478 @return pointer to allocated memory. */
479 void *alloc(size_t n_bytes) noexcept {
480 ut_ad(n_bytes > 0);
481 return mem_heap_alloc(get(), n_bytes);
482 }
483
484 private:
485 /** A functor with no state to be used for mem_heap destruction. */
487 void operator()(mem_heap_t *heap) { mem_heap_free(heap); }
488 };
489
490 using Ptr = std::unique_ptr<Type, mem_heap_free_functor>;
491
492 /** Heap to use. */
494
496 Scoped_heap(const Scoped_heap &) = delete;
499};
500
501#endif
A C++ wrapper class to the mem_heap_t routines, so that it can be used as an STL allocator.
Definition: mem0mem.h:351
void destroy(pointer p)
Definition: mem0mem.h:398
const T & const_reference
Definition: mem0mem.h:359
size_t size_type
Definition: mem0mem.h:354
~mem_heap_allocator()
Definition: mem0mem.h:373
const T * const_pointer
Definition: mem0mem.h:357
size_type max_size() const
Definition: mem0mem.h:375
mem_heap_t * m_heap
Definition: mem0mem.h:416
mem_heap_allocator(const mem_heap_allocator< U > &other)
Definition: mem0mem.h:368
T value_type
Definition: mem0mem.h:353
mem_heap_allocator(const mem_heap_allocator &other)
Definition: mem0mem.h:363
mem_heap_t * get_mem_heap() const
Get the underlying memory heap object.
Definition: mem0mem.h:413
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:384
T & reference
Definition: mem0mem.h:358
ptrdiff_t difference_type
Definition: mem0mem.h:355
void deallocate(pointer, size_type)
Definition: mem0mem.h:388
T * pointer
Definition: mem0mem.h:356
const_pointer address(const_reference r) const
Definition: mem0mem.h:392
void construct(pointer p, const_reference t)
Definition: mem0mem.h:394
mem_heap_allocator(mem_heap_t *heap)
Definition: mem0mem.h:361
pointer address(reference r) const
Definition: mem0mem.h:390
const char * p
Definition: ctype-mb.cc:1236
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
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:54
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:194
bool operator!=(const mem_heap_allocator< T > &left, const mem_heap_allocator< T > &right)
Definition: mem0mem.h:428
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:422
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:66
constexpr int MEM_NO_MANS_LAND
Definition: mem0mem.h:100
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...
constexpr uint64_t MEM_BLOCK_MAGIC_N
Definition: mem0mem.h:339
static uint64_t MEM_SPACE_NEEDED(uint64_t N)
Space needed when allocating for a user a field of length N.
Definition: mem0mem.h:113
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:66
const byte MEM_NO_MANS_LAND_BEFORE_BYTE
Definition: mem0mem.h:106
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:73
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:69
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:56
constexpr uint64_t MEM_FREED_BLOCK_MAGIC_N
Definition: mem0mem.h:340
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:79
char * mem_heap_strdup(mem_heap_t *heap, const char *str)
Duplicates a NUL-terminated string, allocated from a memory heap.
Definition: memory.cc:50
void mem_heap_validate(const mem_heap_t *heap)
Validates the contents of a memory heap.
Definition: memory.cc:222
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:108
constexpr uint32_t MEM_HEAP_FOR_RECV_SYS
Definition: mem0mem.h:72
static ulint mem_heap_get_size(mem_heap_t *heap)
Returns the space in bytes occupied by a memory heap.
constexpr uint32_t MEM_HEAP_BUFFER
Definition: mem0mem.h:62
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:61
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:71
static char * mem_strdupl(const char *str, ulint len)
Makes a NUL-terminated copy of a nonterminated string.
The memory management.
std::atomic< Type > N
Definition: ut0counter.h:224
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
Definition: buf0block_hint.cc:29
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2859
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
required string type
Definition: replication_group_member_actions.proto:33
A functor with no state to be used for mem_heap destruction.
Definition: mem0mem.h:486
void operator()(mem_heap_t *heap)
Definition: mem0mem.h:487
Heap wrapper that destroys the heap instance when it goes out of scope.
Definition: mem0mem.h:434
Scoped_heap(size_t n, ut::Location location) noexcept
Constructs heap with a free space of specified size.
Definition: mem0mem.h:443
void * alloc(size_t n_bytes) noexcept
Allocate memory in the heap.
Definition: mem0mem.h:479
~Scoped_heap()=default
Destructor.
Scoped_heap()
Default constructor.
Definition: mem0mem.h:438
Scoped_heap(const Scoped_heap &)=delete
void clear() noexcept
Empty the heap.
Definition: mem0mem.h:470
std::unique_ptr< Type, mem_heap_free_functor > Ptr
Definition: mem0mem.h:490
void reset(Type *p)
Set the pointer to p.
Definition: mem0mem.h:463
Scoped_heap & operator=(Scoped_heap &&)=delete
Ptr m_ptr
Heap to use.
Definition: mem0mem.h:493
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:452
Type * get() noexcept
Definition: mem0mem.h:459
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:299
ulint start
the value of the struct field 'free' at the creation of the block
Definition: mem0mem.h:326
ulint len
physical length of this block in bytes
Definition: mem0mem.h:316
void * buf_block
if this block has been allocated from the buffer pool, this contains the buf_block_t handle; otherwis...
Definition: mem0mem.h:333
ulint total_size
physical length in bytes of all blocks in the heap.
Definition: mem0mem.h:319
char file_name[16]
file name where the mem heap was created
Definition: mem0mem.h:304
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:306
uint64_t magic_n
magic number for debugging
Definition: mem0mem.h:301
ulint type
type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to MEM_HEAP_BTR_SEARCH
Definition: mem0mem.h:322
UT_LIST_NODE_T(mem_block_t) list
This contains pointers to next and prev in the list.
std::atomic< void * > free_block
if the MEM_HEAP_BTR_SEARCH bit is set in type, and this is the heap root, this can contain an allocat...
Definition: mem0mem.h:330
ulint free
offset in bytes of the first free position for user data in the block
Definition: mem0mem.h:324
Allocators are required to supply the below template class member which enables the possibility of ob...
Definition: mem0mem.h:407
mem_heap_allocator< U > other
Definition: mem0mem.h:408
Definition: ut0core.h:32
unsigned long int ulint
Definition: univ.i:407
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:284
Utilities for byte operations.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:56
#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:269
Memory primitives.
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:171
int n
Definition: xcom_base.cc:505