MySQL 8.1.0
Source Code Documentation
mem0mem.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2023, 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 size_t 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
298struct buf_block_t;
299
300/** The info structure stored at the beginning of a heap block */
302 /** Magic number for debugging. */
303 uint64_t magic_n;
304#ifdef UNIV_DEBUG
305 /** File name where the mem heap was created. */
306 char file_name[16];
307 /** Line number where the mem heap was created. */
309#endif /* UNIV_DEBUG */
310 /** This contains pointers to next and prev in the list. The first block
311 allocated to the heap is also the first block in this list,
312 though it also contains the base node of the list. */
314 /** In the first block of the list this is the base node of the list of
315 blocks; in subsequent blocks this is undefined. */
317 /** Physical length of this block in bytes. */
319 /** Physical length in bytes of all blocks in the heap. This is defined only
320 in the base node and is set to ULINT_UNDEFINED in others. */
322 /** Type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to
323 MEM_HEAP_BTR_SEARCH. */
325 /** Offset in bytes of the first free position for user data in the block. */
327 /** The value of the struct field 'free' at the creation of the block. */
329 /* This is not null iff the MEM_HEAP_BTR_SEARCH bit is set in type, and this
330 is the heap root. This leads to a atomic pointer that can contain an allocated
331 buffer frame, which can be appended as a free block to the heap, if we need
332 more space. */
333 std::atomic<buf_block_t *> *free_block_ptr;
334
335 /* if this block has been allocated from the buffer pool, this contains the
336 buf_block_t handle; otherwise, this is NULL */
338};
339/* We use the UT_LIST_BASE_NODE_T_EXTERN instead of simpler UT_LIST_BASE_NODE_T
340because DevStudio12.6 initializes the pointer-to-member offset to 0 otherwise.*/
342
343constexpr uint64_t MEM_BLOCK_MAGIC_N = 0x445566778899AABB;
344constexpr uint64_t MEM_FREED_BLOCK_MAGIC_N = 0xBBAA998877665544;
345
346/* Header size for a memory heap block */
347#define MEM_BLOCK_HEADER_SIZE \
348 ut_calc_align(sizeof(mem_block_info_t), UNIV_MEM_ALIGNMENT)
349
350#include "mem0mem.ic"
351
352/** A C++ wrapper class to the mem_heap_t routines, so that it can be used
353as an STL allocator */
354template <typename T>
356 public:
357 typedef T value_type;
358 typedef size_t size_type;
359 typedef ptrdiff_t difference_type;
360 typedef T *pointer;
361 typedef const T *const_pointer;
362 typedef T &reference;
363 typedef const T &const_reference;
364
366
368 // Do nothing
369 }
370
371 template <typename U>
373 : m_heap(other.m_heap) {
374 // Do nothing
375 }
376
378
379 size_type max_size() const { return (ULONG_MAX / sizeof(T)); }
380
381 /** This function returns a pointer to the first element of a newly
382 allocated array large enough to contain n objects of type T; only the
383 memory is allocated, and the objects are not constructed. Moreover,
384 an optional pointer argument (that points to an object already
385 allocated by mem_heap_allocator) can be used as a hint to the
386 implementation about where the new memory should be allocated in
387 order to improve locality. */
388 pointer allocate(size_type n, const_pointer hint [[maybe_unused]] = nullptr) {
389 return (reinterpret_cast<pointer>(mem_heap_alloc(m_heap, n * sizeof(T))));
390 }
391
393
394 pointer address(reference r) const { return (&r); }
395
397
399 new (reinterpret_cast<void *>(p)) T(t);
400 }
401
402 void destroy(pointer p) { (reinterpret_cast<T *>(p))->~T(); }
403
404 /** Allocators are required to supply the below template class member
405 which enables the possibility of obtaining a related allocator,
406 parametrized in terms of a different type. For example, given an
407 allocator type IntAllocator for objects of type int, a related
408 allocator type for objects of type long could be obtained using
409 IntAllocator::rebind<long>::other */
410 template <typename U>
411 struct rebind {
413 };
414
415 /** Get the underlying memory heap object.
416 @return the underlying memory heap object. */
417 mem_heap_t *get_mem_heap() const { return (m_heap); }
418
419 private:
421 template <typename U>
422 friend class mem_heap_allocator;
423};
424
425template <class T>
427 const mem_heap_allocator<T> &right) {
428 return (left.get_mem_heap() == right.get_mem_heap());
429}
430
431template <class T>
433 const mem_heap_allocator<T> &right) {
434 return (left.get_mem_heap() != right.get_mem_heap());
435}
436
437/** Heap wrapper that destroys the heap instance when it goes out of scope. */
440
441 /** Default constructor. */
443
444 /** Constructs heap with a free space of specified size.
445 @param[in] n Initial size of the heap to allocate.
446 @param[in] location Location from where called. */
447 Scoped_heap(size_t n, ut::Location location) noexcept
448 : m_ptr(mem_heap_create(n, location, MEM_HEAP_DYNAMIC)) {}
449
450 /** Destructor. */
451 ~Scoped_heap() = default;
452
453 /** Create the heap, it must not already be created.
454 @param[in] n Initial size of the heap to allocate.
455 @param[in] location Location from where called. */
456 void create(size_t n, ut::Location location) noexcept {
457 ut_a(get() == nullptr);
458 auto ptr = mem_heap_create(n, location, MEM_HEAP_DYNAMIC);
459 reset(ptr);
460 }
461
462 /** @return the heap pointer. */
463 Type *get() noexcept { return m_ptr.get(); }
464
465 /** Set the pointer to p.
466 @param[in] p New pointer value. */
467 void reset(Type *p) {
468 if (get() != p) {
469 m_ptr.reset(p);
470 }
471 }
472
473 /** Empty the heap. */
474 void clear() noexcept {
475 if (get() != nullptr) {
477 }
478 }
479
480 /** Allocate memory in the heap.
481 @param[in] n_bytes Number of bytes to allocate.
482 @return pointer to allocated memory. */
483 void *alloc(size_t n_bytes) noexcept {
484 ut_ad(n_bytes > 0);
485 return mem_heap_alloc(get(), n_bytes);
486 }
487
488 private:
489 /** A functor with no state to be used for mem_heap destruction. */
491 void operator()(mem_heap_t *heap) { mem_heap_free(heap); }
492 };
493
494 using Ptr = std::unique_ptr<Type, mem_heap_free_functor>;
495
496 /** Heap to use. */
498
500 Scoped_heap(const Scoped_heap &) = delete;
503};
504
505#endif
A C++ wrapper class to the mem_heap_t routines, so that it can be used as an STL allocator.
Definition: mem0mem.h:355
void destroy(pointer p)
Definition: mem0mem.h:402
const T & const_reference
Definition: mem0mem.h:363
size_t size_type
Definition: mem0mem.h:358
~mem_heap_allocator()
Definition: mem0mem.h:377
const T * const_pointer
Definition: mem0mem.h:361
size_type max_size() const
Definition: mem0mem.h:379
mem_heap_t * m_heap
Definition: mem0mem.h:420
mem_heap_allocator(const mem_heap_allocator< U > &other)
Definition: mem0mem.h:372
T value_type
Definition: mem0mem.h:357
mem_heap_allocator(const mem_heap_allocator &other)
Definition: mem0mem.h:367
mem_heap_t * get_mem_heap() const
Get the underlying memory heap object.
Definition: mem0mem.h:417
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:388
T & reference
Definition: mem0mem.h:362
ptrdiff_t difference_type
Definition: mem0mem.h:359
void deallocate(pointer, size_type)
Definition: mem0mem.h:392
T * pointer
Definition: mem0mem.h:360
const_pointer address(const_reference r) const
Definition: mem0mem.h:396
void construct(pointer p, const_reference t)
Definition: mem0mem.h:398
mem_heap_allocator(mem_heap_t *heap)
Definition: mem0mem.h:365
pointer address(reference r) const
Definition: mem0mem.h:394
const char * p
Definition: ctype-mb.cc:1234
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:432
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:426
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...
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:343
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:344
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
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:2877
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:490
void operator()(mem_heap_t *heap)
Definition: mem0mem.h:491
Heap wrapper that destroys the heap instance when it goes out of scope.
Definition: mem0mem.h:438
Scoped_heap(size_t n, ut::Location location) noexcept
Constructs heap with a free space of specified size.
Definition: mem0mem.h:447
void * alloc(size_t n_bytes) noexcept
Allocate memory in the heap.
Definition: mem0mem.h:483
~Scoped_heap()=default
Destructor.
Scoped_heap()
Default constructor.
Definition: mem0mem.h:442
Scoped_heap(const Scoped_heap &)=delete
void clear() noexcept
Empty the heap.
Definition: mem0mem.h:474
std::unique_ptr< Type, mem_heap_free_functor > Ptr
Definition: mem0mem.h:494
void reset(Type *p)
Set the pointer to p.
Definition: mem0mem.h:467
Scoped_heap & operator=(Scoped_heap &&)=delete
Ptr m_ptr
Heap to use.
Definition: mem0mem.h:497
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:456
Type * get() noexcept
Definition: mem0mem.h:463
The buffer control block structure.
Definition: buf0buf.h:1689
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:301
ulint start
The value of the struct field 'free' at the creation of the block.
Definition: mem0mem.h:328
ulint len
Physical length of this block in bytes.
Definition: mem0mem.h:318
std::atomic< buf_block_t * > * free_block_ptr
Definition: mem0mem.h:333
ulint total_size
Physical length in bytes of all blocks in the heap.
Definition: mem0mem.h:321
char file_name[16]
File name where the mem heap was created.
Definition: mem0mem.h:306
buf_block_t * buf_block
Definition: mem0mem.h:337
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:308
uint64_t magic_n
Magic number for debugging.
Definition: mem0mem.h:303
ulint type
Type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to MEM_HEAP_BTR_SEARCH.
Definition: mem0mem.h:324
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:326
Allocators are required to supply the below template class member which enables the possibility of ob...
Definition: mem0mem.h:411
mem_heap_allocator< U > other
Definition: mem0mem.h:412
Definition: ut0core.h:35
unsigned long int ulint
Definition: univ.i:405
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:282
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:508