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