MySQL 9.1.0
Source Code Documentation
mem0mem.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2024, 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/** Concatenate two strings and return the result, using a memory heap.
261 @return own: the result */
262char *mem_heap_strcat(
263 mem_heap_t *heap, /*!< in: memory heap where string is allocated */
264 const char *s1, /*!< in: string 1 */
265 const char *s2); /*!< in: string 2 */
266
267/** Duplicate a block of data, allocated from a memory heap.
268 @return own: a copy of the data */
269void *mem_heap_dup(
270 mem_heap_t *heap, /*!< in: memory heap where copy is allocated */
271 const void *data, /*!< in: data to be copied */
272 ulint len); /*!< in: length of data, in bytes */
273
274/** A simple sprintf replacement that dynamically allocates the space for the
275 formatted string from the given heap. This supports a very limited set of
276 the printf syntax: types 's' and 'u' and length modifier 'l' (which is
277 required for the 'u' type).
278 @return heap-allocated formatted string */
279char *mem_heap_printf(mem_heap_t *heap, /*!< in: memory heap */
280 const char *format, /*!< in: format string */
281 ...) MY_ATTRIBUTE((format(printf, 2, 3)));
282
283/** Checks that an object is a memory heap (or a block of it)
284@param[in] heap Memory heap to check */
285static inline void mem_block_validate(const mem_heap_t *heap);
286
287#ifdef UNIV_DEBUG
288
289/** Validates the contents of a memory heap.
290Checks a memory heap for consistency, prints the contents if any error
291is detected. A fatal error is logged if an error is detected.
292@param[in] heap Memory heap to validate. */
293void mem_heap_validate(const mem_heap_t *heap);
294
295#endif /* UNIV_DEBUG */
296
297/*#######################################################################*/
298
299struct buf_block_t;
300
301/** The info structure stored at the beginning of a heap block */
303 /** Magic number for debugging. */
304 uint64_t magic_n;
305#ifdef UNIV_DEBUG
306 /** File name where the mem heap was created. */
307 char file_name[16];
308 /** Line number where the mem heap was created. */
310#endif /* UNIV_DEBUG */
311 /** This contains pointers to next and prev in the list. The first block
312 allocated to the heap is also the first block in this list,
313 though it also contains the base node of the list. */
315 /** In the first block of the list this is the base node of the list of
316 blocks; in subsequent blocks this is undefined. */
318 /** Physical length of this block in bytes. */
320 /** Physical length in bytes of all blocks in the heap. This is defined only
321 in the base node and is set to ULINT_UNDEFINED in others. */
323 /** Type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to
324 MEM_HEAP_BTR_SEARCH. */
326 /** Offset in bytes of the first free position for user data in the block. */
328 /** The value of the struct field 'free' at the creation of the block. */
330 /* This is not null iff the MEM_HEAP_BTR_SEARCH bit is set in type, and this
331 is the heap root. This leads to a atomic pointer that can contain an allocated
332 buffer frame, which can be appended as a free block to the heap, if we need
333 more space. */
334 std::atomic<buf_block_t *> *free_block_ptr;
335
336 /* if this block has been allocated from the buffer pool, this contains the
337 buf_block_t handle; otherwise, this is NULL */
339};
340/* We use the UT_LIST_BASE_NODE_T_EXTERN instead of simpler UT_LIST_BASE_NODE_T
341because DevStudio12.6 initializes the pointer-to-member offset to 0 otherwise.*/
343
344constexpr uint64_t MEM_BLOCK_MAGIC_N = 0x445566778899AABB;
345constexpr uint64_t MEM_FREED_BLOCK_MAGIC_N = 0xBBAA998877665544;
346
347/* Header size for a memory heap block */
348#define MEM_BLOCK_HEADER_SIZE \
349 ut_calc_align(sizeof(mem_block_info_t), UNIV_MEM_ALIGNMENT)
350
351#include "mem0mem.ic"
352
353/** A C++ wrapper class to the mem_heap_t routines, so that it can be used
354as an STL allocator */
355template <typename T>
357 public:
358 typedef T value_type;
359 typedef size_t size_type;
360 typedef ptrdiff_t difference_type;
361 typedef T *pointer;
362 typedef const T *const_pointer;
363 typedef T &reference;
364 typedef const T &const_reference;
365
367
369 // Do nothing
370 }
371
372 template <typename U>
374 : m_heap(other.m_heap) {
375 // Do nothing
376 }
377
379
380 size_type max_size() const { return (ULONG_MAX / sizeof(T)); }
381
382 /** This function returns a pointer to the first element of a newly
383 allocated array large enough to contain n objects of type T; only the
384 memory is allocated, and the objects are not constructed. Moreover,
385 an optional pointer argument (that points to an object already
386 allocated by mem_heap_allocator) can be used as a hint to the
387 implementation about where the new memory should be allocated in
388 order to improve locality. */
389 pointer allocate(size_type n, const_pointer hint [[maybe_unused]] = nullptr) {
390 return (reinterpret_cast<pointer>(mem_heap_alloc(m_heap, n * sizeof(T))));
391 }
392
394
395 pointer address(reference r) const { return (&r); }
396
398
400 new (reinterpret_cast<void *>(p)) T(t);
401 }
402
403 void destroy(pointer p) { (reinterpret_cast<T *>(p))->~T(); }
404
405 /** Allocators are required to supply the below template class member
406 which enables the possibility of obtaining a related allocator,
407 parametrized in terms of a different type. For example, given an
408 allocator type IntAllocator for objects of type int, a related
409 allocator type for objects of type long could be obtained using
410 IntAllocator::rebind<long>::other */
411 template <typename U>
412 struct rebind {
414 };
415
416 /** Get the underlying memory heap object.
417 @return the underlying memory heap object. */
418 mem_heap_t *get_mem_heap() const { return (m_heap); }
419
420 private:
422 template <typename U>
423 friend class mem_heap_allocator;
424};
425
426template <class T>
428 const mem_heap_allocator<T> &right) {
429 return (left.get_mem_heap() == right.get_mem_heap());
430}
431
432template <class T>
434 const mem_heap_allocator<T> &right) {
435 return (left.get_mem_heap() != right.get_mem_heap());
436}
437
438/** Heap wrapper that destroys the heap instance when it goes out of scope. */
441
442 /** Default constructor. */
444
445 /** Constructs heap with a free space of specified size.
446 @param[in] n Initial size of the heap to allocate.
447 @param[in] location Location from where called. */
448 Scoped_heap(size_t n, ut::Location location) noexcept
449 : m_ptr(mem_heap_create(n, location, MEM_HEAP_DYNAMIC)) {}
450
451 /** Destructor. */
452 ~Scoped_heap() = default;
453
454 /** Create the heap, it must not already be created.
455 @param[in] n Initial size of the heap to allocate.
456 @param[in] location Location from where called. */
457 void create(size_t n, ut::Location location) noexcept {
458 ut_a(is_null());
459 auto ptr = mem_heap_create(n, location, MEM_HEAP_DYNAMIC);
460 reset(ptr);
461 }
462
463 /** Check if the memory heap has been created.
464 @return true if memory heap is not created, false if memory heap is created.*/
465 bool is_null() const noexcept { return m_ptr.get() == nullptr; }
466
467 /** @return the heap pointer. */
468 Type *get() noexcept {
469 ut_ad(!is_null());
470 return m_ptr.get();
471 }
472
473 /** Set the pointer to p.
474 @param[in] p New pointer value. */
475 void reset(Type *p) {
476 if (m_ptr.get() != p) {
477 m_ptr.reset(p);
478 }
479 }
480
481 /** Empty the heap. */
482 void clear() noexcept {
483 if (!is_null()) {
485 }
486 }
487
488 /** Allocate memory in the heap.
489 @param[in] n_bytes Number of bytes to allocate.
490 @return pointer to allocated memory. */
491 void *alloc(size_t n_bytes) noexcept {
492 ut_ad(n_bytes > 0);
493 return mem_heap_alloc(get(), n_bytes);
494 }
495
496 private:
497 /** A functor with no state to be used for mem_heap destruction. */
499 void operator()(mem_heap_t *heap) { mem_heap_free(heap); }
500 };
501
502 using Ptr = std::unique_ptr<Type, mem_heap_free_functor>;
503
504 /** Heap to use. */
506
508 Scoped_heap(const Scoped_heap &) = delete;
511};
512
513#endif
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
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:1225
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.
The memory management.
std::atomic< Type > N
Definition: ut0counter.h:225
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
Definition: buf0block_hint.cc:30
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:2880
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:498
void operator()(mem_heap_t *heap)
Definition: mem0mem.h:499
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:491
~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:482
bool is_null() const noexcept
Check if the memory heap has been created.
Definition: mem0mem.h:465
std::unique_ptr< Type, mem_heap_free_functor > Ptr
Definition: mem0mem.h:502
void reset(Type *p)
Set the pointer to p.
Definition: mem0mem.h:475
Scoped_heap & operator=(Scoped_heap &&)=delete
Ptr m_ptr
Heap to use.
Definition: mem0mem.h:505
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:468
The buffer control block structure.
Definition: buf0buf.h:1747
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
Definition: ut0core.h:36
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:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
#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:178
int n
Definition: xcom_base.cc:509