MySQL 9.0.0
Source Code Documentation
unique_ptr.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MEMORY_UNIQUE_PTR_INCLUDED
25#define MEMORY_UNIQUE_PTR_INCLUDED
26
27#include <assert.h>
28#include <sys/stat.h>
29#include <sys/types.h>
30#include <algorithm>
31#include <cstddef>
32#include <iostream>
33#include <limits>
34#include <memory>
35#include <string>
36#include <tuple>
37
38#include "my_sys.h"
39#include "mysql/service_mysql_alloc.h" // my_malloc
40#include "sql/memory/aligned_atomic.h" // memory::cache_line_size
41#include "sql/memory/ref_ptr.h" // memory::Ref_ptr
42
43namespace memory {
44namespace traits {
45/**
46 Tests for the existence of `allocate(size_t)` in order to disambiguate if `T`
47 is an allocator class.
48 */
49template <class T>
50auto test_for_allocate(int T::*)
51 -> decltype(std::declval<T>().allocate(std::declval<size_t>()),
52 std::true_type{});
53template <class>
54std::false_type test_for_allocate(...);
55
56} // namespace traits
57/**
58 Struct that allows for checking if `T` fulfills the Allocator named
59 requirements.
60 */
61template <class T>
62struct is_allocator : decltype(traits::test_for_allocate<T>(nullptr)) {};
63
64/**
65 Allocator class for instrumenting allocated memory with Performance Schema
66 keys.
67 */
68template <typename T>
70 using value_type = T;
71 using size_type = size_t;
72
73 /**
74 Constructor for the class that takes the PFS key to be used.
75
76 @param key The PFS key to be used.
77 */
79 /**
80 Copy constructor.
81
82 @param rhs The object to copy from.
83 */
84 template <typename U>
85 PFS_allocator(PFS_allocator<U> const &rhs) noexcept;
86 /**
87 Move constructor.
88
89 @param rhs The object to move from.
90 */
91 template <typename U>
92 PFS_allocator(PFS_allocator<U> &&rhs) noexcept;
93 /**
94 Retrieves the PFS for `this` allocator object.
95
96 @return The PFS key.
97 */
98 PSI_memory_key key() const;
99 /**
100 Allocate `n` bytes and return a pointer to the beginning of the allocated
101 memory.
102
103 @param n The size of the memory to allocate.
104
105 @return A pointer to the beginning of the allocated memory.
106 */
107 T *allocate(std::size_t n);
108 /**
109 Deallocates the `n` bytes stored in the memory pointer `p` is pointing to.
110
111 @param p The pointer to the beginning of the memory to deallocate.
112 @param n The size of the memory to deallocate.
113 */
114 void deallocate(T *p, std::size_t n) noexcept;
115 /**
116 In-place constructs an object of class `U` in the memory pointed by `p`.
117
118 @param p The pointer to the beginning of the memory to construct the object
119 in.
120 @param args The parameters to be used with the `U` constructor.
121 */
122 template <class U, class... Args>
123 void construct(U *p, Args &&... args);
124 /**
125 In-place invokes the destructor for class `T` on object pointed by `p`.
126
127 @param p The object pointer to invoke the destructor on.
128 */
129 void destroy(T *p);
130 /**
131 The maximum size available to allocate.
132
133 @return The maximum size available to allocate.
134 */
135 size_type max_size() const;
136
137 private:
138 /** The PFS key to be used to allocate memory */
140};
141
142/**
143 Smart pointer to hold a unique pointer to a heap allocated memory of type `T`,
144 constructed using a specific allocator.
145
146 Template parameters are as follows:
147 - `T` is the type of the pointer to allocate. It may be an array type.
148 - `A` the allocator to use. If none is passed, `std::nullptr_t` is passed and
149 regular `new` and `delete` are used to construct the memory.
150 */
151template <typename T, typename A = std::nullptr_t>
153 public:
155 using pointer = type *;
156 using reference = type &;
157
158 /**
159 Default class constructor, only to be used with no specific allocator.
160 */
161 template <
162 typename D = T, typename B = A,
163 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> * = nullptr>
164 Unique_ptr();
165 /**
166 Class constructor, to be used with specific allocators, passing the
167 allocator object to be used.
168
169 @param alloc The allocator instance to be used.
170 */
171 template <
172 typename D = T, typename B = A,
173 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> * = nullptr>
174 Unique_ptr(A &alloc);
175 /**
176 Class constructor, to be used with specific allocators and when `T` is an
177 array type, passing the allocator object to be used and the size of the
178 array.
179
180 @param alloc The allocator instance to be used.
181 @param size The size of the array to allocate.
182 */
183 template <typename D = T, typename B = A,
184 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
185 std::is_array<D>::value> * = nullptr>
186 Unique_ptr(A &alloc, size_t size);
187 /**
188 Class constructor, to be used with no specific allocators and when `T` is an
189 array type, passing the allocator object to be used and the size of the
190 array.
191
192 @param size The size of the array to allocate.
193 */
194 template <typename D = T, typename B = A,
195 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
196 std::is_array<D>::value> * = nullptr>
197 Unique_ptr(size_t size);
198 /**
199 Class constructor, to be used with specific allocators and when `T` is not
200 an array type, passing the allocator object to be used and the parameters to
201 be used with `T` object constructor.
202
203 @param alloc The allocator instance to be used.
204 @param args The parameters to be used with `T` object constructor.
205 */
206 template <typename... Args, typename D = T, typename B = A,
207 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
208 !std::is_array<D>::value> * = nullptr>
209 Unique_ptr(A &alloc, Args &&... args);
210 /**
211 Class constructor, to be used with no specific allocators and when `T` is
212 not an array type, passing the parameters to be used with `T` object
213 constructor.
214
215 @param args The parameters to be used with `T` object constructor.
216 */
217 template <typename... Args, typename D = T, typename B = A,
218 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
219 !std::is_array<D>::value> * = nullptr>
220 Unique_ptr(Args &&... args);
221 // Deleted copy constructor
222 Unique_ptr(Unique_ptr<T, A> const &rhs) = delete;
223 /**
224 Move constructor.
225
226 @param rhs The object to move data from.
227 */
229 /**
230 Destructor for the class.
231 */
232 virtual ~Unique_ptr();
233 // Deleted copy operator
235 /**
236 Move operator.
237
238 @param rhs The object to move data from.
239 */
241 /**
242 Arrow operator to access the underlying object of type `T`.
243
244 @return A pointer to the underlying object of type `T`.
245 */
246 template <typename D = T,
247 std::enable_if_t<!std::is_array<D>::value> * = nullptr>
249 /**
250 Star operator to access the underlying object of type `T`.
251
252 @return A reference to the underlying object of type `T`.
253 */
254 reference operator*() const;
255 /**
256 Subscript operator, to access an array element when `T` is of array type.
257
258 @param index The index of the element to retrieve the value for.
259
260 @return A reference to the value stored at index.
261 */
262 template <typename D = T,
263 std::enable_if_t<std::is_array<D>::value> * = nullptr>
264 reference operator[](size_t index) const;
265 /**
266 Casting operator to bool.
267
268 @return `true` if the underlying pointer is instantiated, `false` otherwise.
269 */
270 operator bool() const;
271 /**
272 Releases the ownership of the underlying allocated memory and returns a
273 pointer to the beginning of that memory. This smart pointer will no longer
274 manage the underlying memory.
275
276 @return the pointer to the allocated and no longer managed memory.
277 */
278 template <
279 typename B = A,
280 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> * = nullptr>
282 /**
283 Releases the ownership of the underlying allocated memory and returns a
284 pointer to the beginning of that memory. This smart pointer will no longer
285 manage the underlying memory.
286
287 @return the pointer to the allocated and no longer managed memory.
288 */
289 template <
290 typename B = A,
291 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> * = nullptr>
293 /**
294 Returns a pointer to the underlying allocated memory.
295
296 @return A pointer to the underlying allocated memory
297 */
298 pointer get() const;
299 /**
300 The size of the memory allocated, in bytes.
301
302 @return The size of the memory allocated, in bytes
303 */
304 size_t size() const;
305 /**
306 Will resize the allocated memory to `new_size`. If the configure allocator
307 supports this operation, the allocator is used. If not, a new memory chunk
308 is allocated and the memory is copied.
309
310 @param new_size The new desired size for the memory.
311
312 @return The reference to `this` object, for chaining purposed.
313 */
314 template <
315 typename D = T, typename B = A,
316 std::enable_if_t<std::is_array<D>::value &&
317 std::is_same<B, std::nullptr_t>::value> * = nullptr>
318 Unique_ptr<T, A> &reserve(size_t new_size);
319 /**
320 Will resize the allocated memory to `new_size`. If the configure allocator
321 supports this operation, the allocator is used. If not, a new memory chunk
322 is allocated and the memory is copied.
323
324 @param new_size The new desired size for the memory.
325
326 @return The reference to `this` object, for chaining purposed.
327 */
328 template <
329 typename D = T, typename B = A,
330 std::enable_if_t<std::is_array<D>::value &&
331 !std::is_same<B, std::nullptr_t>::value> * = nullptr>
332 Unique_ptr<T, A> &reserve(size_t new_size);
333 /**
334 Returns the used allocator instance, if any.
335
336 @return The reference to the allocator object.
337 */
338 A &allocator() const;
339
340 private:
341 /** The pointer to the underlying allocated memory */
342 alignas(std::max_align_t) pointer m_underlying{nullptr};
343 /** The allocator to be used to allocate memory */
345 /** The size of the allocated memory */
346 size_t m_size{0};
347
348 /**
349 Clears the underlying pointer and size.
350 */
351 void reset();
352 /**
353 Deallocates the underlying allocated memory.
354 */
355 template <typename D = T, typename B = A,
356 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
357 std::is_array<D>::value> * = nullptr>
358 void destroy();
359 /**
360 Deallocates the underlying allocated memory.
361 */
362 template <typename D = T, typename B = A,
363 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
364 !std::is_array<D>::value> * = nullptr>
365 void destroy();
366 /**
367 Deallocates the underlying allocated memory.
368 */
369 template <typename D = T, typename B = A,
370 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
371 std::is_array<D>::value> * = nullptr>
372 void destroy();
373 /**
374 Deallocates the underlying allocated memory.
375 */
376 template <typename D = T, typename B = A,
377 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
378 !std::is_array<D>::value> * = nullptr>
379 void destroy();
380 /**
381 Clones the underlying memory and returns a pointer to the clone memory.
382
383 @return A pointer to the cloned underlying memory.
384 */
385 template <typename D = T,
386 std::enable_if_t<std::is_array<D>::value> * = nullptr>
387 pointer clone() const;
388 /**
389 Clones the underlying memory and returns a pointer to the clone memory.
390
391 @return A pointer to the cloned underlying memory.
392 */
393 template <typename D = T,
394 std::enable_if_t<!std::is_array<D>::value> * = nullptr>
395 pointer clone() const;
396};
397
398/**
399 In-place constructs a new unique pointer with no specific allocator and with
400 array type `T`.
401
402 @param size The size of the array to allocate.
403
404 @return A new instance of unique pointer.
405 */
406template <typename T, std::enable_if_t<std::is_array<T>::value> * = nullptr>
408/**
409 In-place constructs a new unique pointer with a specific allocator and with
410 array type `T`.
411
412 @param alloc A reference to the allocator object to use.
413 @param size The size of the array to allocate.
414
415 @return A new instance of unique pointer.
416 */
417template <typename T, typename A,
418 std::enable_if_t<std::is_array<T>::value> * = nullptr>
420/**
421 In-place constructs a new unique pointer with a specific allocator and with
422 non-array type `T`.
423
424 @param alloc A reference to the allocator object to use.
425 @param args The parameters to be used in constructing the instance of `T`.
426
427 @return A new instance of unique pointer.
428 */
429template <typename T, typename A, typename... Args,
430 std::enable_if_t<!std::is_array<T>::value &&
432Unique_ptr<T, A> make_unique(A &alloc, Args &&... args);
433/**
434 In-place constructs a new unique pointer with no specific allocator and with
435 non-array type `T`.
436
437 @param args The parameters to be used in constructing the instance of `T`.
438
439 @return A new instance of unique pointer.
440 */
441template <typename T, typename... Args,
442 std::enable_if_t<!std::is_array<T>::value> * = nullptr>
444} // namespace memory
445
446// global scope
447template <typename T, typename U>
449 const memory::PFS_allocator<U> &rhs) {
450 return lhs.key() == rhs.key();
451}
452
453template <typename T, typename U>
455 const memory::PFS_allocator<U> &rhs) {
456 return lhs.key() != rhs.key();
457}
458
459template <typename T1, typename A1, typename T2, typename A2>
461 memory::Unique_ptr<T2, A2> const &rhs) {
462 return static_cast<const void *>(lhs.get()) ==
463 static_cast<const void *>(rhs.get());
464}
465
466template <typename T1, typename A1, typename T2, typename A2>
468 memory::Unique_ptr<T2, A2> const &rhs) {
469 return !(lhs == rhs);
470}
471
472template <typename T1, typename A1>
473bool operator==(memory::Unique_ptr<T1, A1> const &lhs, std::nullptr_t) {
474 return lhs.get() == nullptr;
475}
476
477template <typename T1, typename A1>
478bool operator!=(memory::Unique_ptr<T1, A1> const &lhs, std::nullptr_t) {
479 return !(lhs == nullptr);
480}
481// global scope
482
483template <typename T>
485
486template <typename T>
487template <typename U>
489 : m_key{rhs.m_key} {}
490
491template <typename T>
492template <typename U>
494 : m_key{rhs.m_key} {
495 rhs.m_key = 0;
496}
497
498template <typename T>
500 return this->m_key;
501}
502
503template <typename T>
505 if (n <= std::numeric_limits<std::size_t>::max() / sizeof(T)) {
506 if (auto p = static_cast<T *>(my_malloc(this->m_key, (n * sizeof(T)),
508 return p;
509 }
510 throw std::bad_alloc();
511}
512
513template <typename T>
514void memory::PFS_allocator<T>::deallocate(T *p, std::size_t) noexcept {
515 my_free(p);
516}
517
518template <typename T>
519template <class U, class... Args>
520void memory::PFS_allocator<T>::construct(U *p, Args &&... args) {
521 assert(p != nullptr);
522 try {
523 ::new ((void *)p) U(std::forward<Args>(args)...);
524 } catch (...) {
525 assert(false); // Constructor should not throw an exception.
526 }
527}
528
529template <typename T>
531 assert(p != nullptr);
532 try {
533 p->~T();
534 } catch (...) {
535 assert(false); // Destructor should not throw an exception
536 }
537}
538
539template <typename T>
541 return std::numeric_limits<size_t>::max() / sizeof(T);
542}
543
544template <typename T, typename A>
545template <typename D, typename B,
546 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> *>
547memory::Unique_ptr<T, A>::Unique_ptr() : m_underlying{nullptr}, m_size{0} {}
548
549template <typename T, typename A>
550template <typename D, typename B,
551 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> *>
553 : m_underlying{nullptr}, m_allocator{alloc}, m_size{0} {}
554
555template <typename T, typename A>
556template <typename D, typename B,
557 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
558 std::is_array<D>::value> *>
560 : m_underlying{nullptr}, m_allocator{alloc}, m_size{size} {
561 this->m_underlying = this->m_allocator->allocate(this->m_size);
562}
563
564template <typename T, typename A>
565template <typename D, typename B,
566 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
567 std::is_array<D>::value> *>
569 : m_underlying{new type[size]}, m_size{size} {}
570
571template <typename T, typename A>
572template <typename... Args, typename D, typename B,
573 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
574 !std::is_array<D>::value> *>
575memory::Unique_ptr<T, A>::Unique_ptr(A &alloc, Args &&... args)
576 : m_underlying{nullptr}, m_allocator{alloc}, m_size{sizeof(T)} {
577 this->m_underlying = this->m_allocator->allocate(this->m_size);
578 this->m_allocator->construct(this->m_underlying, std::forward<Args>(args)...);
579}
580
581template <typename T, typename A>
582template <typename... Args, typename D, typename B,
583 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
584 !std::is_array<D>::value> *>
586 : m_underlying{new T{std::forward<Args>(args)...}}, m_size{sizeof(T)} {}
587
588template <typename T, typename A>
590 : m_underlying{rhs.m_underlying},
591 m_allocator{rhs.m_allocator},
592 m_size{rhs.m_size} {
593 rhs.reset();
594}
595
596template <typename T, typename A>
598 this->destroy();
599}
600
601template <typename T, typename A>
604 this->m_underlying = rhs.m_underlying;
605 this->m_allocator = rhs.m_allocator;
606 this->m_size = rhs.m_size;
607 rhs.reset();
608 return (*this);
609}
610
611template <typename T, typename A>
612template <typename D, std::enable_if_t<!std::is_array<D>::value> *>
615 return this->m_underlying;
616}
617
618template <typename T, typename A>
621 return (*this->m_underlying);
622}
623
624template <typename T, typename A>
625template <typename D, std::enable_if_t<std::is_array<D>::value> *>
628 return this->m_underlying[index];
629}
630
631template <typename T, typename A>
633 return this->m_underlying != nullptr;
634}
635
636template <typename T, typename A>
637template <typename B,
638 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> *>
640 pointer to_return = this->m_underlying;
641 this->reset();
642 return to_return;
643}
644
645template <typename T, typename A>
646template <typename B,
647 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> *>
649 pointer to_return = this->m_allocator->release(this->m_underlying);
650 if (to_return != this->m_underlying) {
651 to_return = this->clone();
652 this->destroy();
653 } else {
654 this->reset();
655 }
656 return to_return;
657}
658
659template <typename T, typename A>
661 const {
662 return this->m_underlying;
663}
664
665template <typename T, typename A>
667 return this->m_size;
668}
669
670template <typename T, typename A>
671template <typename D, typename B,
672 std::enable_if_t<std::is_array<D>::value &&
673 std::is_same<B, std::nullptr_t>::value> *>
675 size_t new_size) {
676 pointer old_ptr = this->m_underlying;
677 this->m_underlying = new type[new_size];
678 if (this->m_size != 0) {
679 std::copy(old_ptr, old_ptr + std::min(this->m_size, new_size),
680 this->m_underlying);
681 }
682 this->m_size = new_size;
683 delete[] old_ptr;
684 return (*this);
685}
686
687template <typename T, typename A>
688template <typename D, typename B,
689 std::enable_if_t<std::is_array<D>::value &&
690 !std::is_same<B, std::nullptr_t>::value> *>
692 size_t new_size) {
693 if (this->m_allocator->can_resize()) {
694 this->m_underlying =
695 this->m_allocator->resize(this->m_underlying, this->m_size, new_size);
696 } else {
697 pointer old_ptr = this->m_underlying;
698 this->m_underlying = this->m_allocator->allocate(new_size);
699 if (this->m_size != 0) {
700 std::copy(old_ptr, old_ptr + std::min(this->m_size, new_size),
701 this->m_underlying);
702 this->m_allocator->deallocate(old_ptr, this->m_size);
703 }
704 }
705 this->m_size = new_size;
706 return (*this);
707}
708
709template <typename T, typename A>
711 return *this->m_allocator;
712}
713
714template <typename T, typename A>
716 this->m_underlying = nullptr;
717 this->m_size = 0;
718}
719
720template <typename T, typename A>
721template <typename D, typename B,
722 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
723 std::is_array<D>::value> *>
725 if (this->m_underlying != nullptr) {
726 delete[] this->m_underlying;
727 this->reset();
728 }
729}
730
731template <typename T, typename A>
732template <typename D, typename B,
733 std::enable_if_t<std::is_same<B, std::nullptr_t>::value &&
734 !std::is_array<D>::value> *>
736 if (this->m_underlying != nullptr) {
737 delete this->m_underlying;
738 this->reset();
739 }
740}
741
742template <typename T, typename A>
743template <typename D, typename B,
744 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
745 std::is_array<D>::value> *>
747 if (this->m_underlying != nullptr) {
748 this->m_allocator->deallocate(this->m_underlying, this->m_size);
749 this->reset();
750 }
751}
752
753template <typename T, typename A>
754template <typename D, typename B,
755 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value &&
756 !std::is_array<D>::value> *>
758 if (this->m_underlying != nullptr) {
759 this->m_allocator->destroy(this->m_underlying);
760 this->m_allocator->deallocate(this->m_underlying, this->m_size);
761 this->reset();
762 }
763}
764
765template <typename T, typename A>
766template <typename D, std::enable_if_t<std::is_array<D>::value> *>
768 const {
769 pointer to_return = new type[this->m_size];
770 std::copy(this->m_underlying, this->m_underlying + this->m_size, to_return);
771 return to_return;
772}
773
774template <typename T, typename A>
775template <typename D, std::enable_if_t<!std::is_array<D>::value> *>
777 const {
778 pointer to_return = new type(*this->m_underlying);
779 return to_return;
780}
781
782#ifndef IN_DOXYGEN // Doxygen doesn't understand this construction.
783template <typename T, std::enable_if_t<std::is_array<T>::value> *>
786}
787
788template <typename T, typename A, std::enable_if_t<std::is_array<T>::value> *>
790 return std::move(memory::Unique_ptr<T, A>{alloc, size});
791}
792
793template <typename T, typename A, typename... Args,
794 std::enable_if_t<!std::is_array<T>::value &&
796memory::Unique_ptr<T, A> memory::make_unique(A &alloc, Args &&... args) {
797 return std::move(
798 memory::Unique_ptr<T, A>{alloc, std::forward<Args>(args)...});
799}
800
801template <typename T, typename... Args,
802 std::enable_if_t<!std::is_array<T>::value> *>
804 return memory::Unique_ptr<T, std::nullptr_t>{std::forward<Args>(args)...};
805}
806#endif
807
808#endif // MEMORY_UNIQUE_PTR_INCLUDED
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
int destroy(azio_stream *s)
Definition: azio.cc:371
Allocator class for instrumenting allocated memory with Performance Schema keys.
Definition: unique_ptr.h:69
size_type max_size() const
The maximum size available to allocate.
Definition: unique_ptr.h:540
size_t size_type
Definition: unique_ptr.h:71
T value_type
Definition: unique_ptr.h:70
PSI_memory_key key() const
Retrieves the PFS for this allocator object.
Definition: unique_ptr.h:499
PSI_memory_key m_key
The PFS key to be used to allocate memory.
Definition: unique_ptr.h:139
void destroy(T *p)
In-place invokes the destructor for class T on object pointed by p.
Definition: unique_ptr.h:530
PFS_allocator(PSI_memory_key key)
Constructor for the class that takes the PFS key to be used.
Definition: unique_ptr.h:484
T * allocate(std::size_t n)
Allocate n bytes and return a pointer to the beginning of the allocated memory.
Definition: unique_ptr.h:504
void deallocate(T *p, std::size_t n) noexcept
Deallocates the n bytes stored in the memory pointer p is pointing to.
Definition: unique_ptr.h:514
void construct(U *p, Args &&... args)
In-place constructs an object of class U in the memory pointed by p.
Definition: unique_ptr.h:520
Class that holds the pointer to a variable in a static and non-destructible way.
Definition: ref_ptr.h:46
Smart pointer to hold a unique pointer to a heap allocated memory of type T, constructed using a spec...
Definition: unique_ptr.h:152
size_t size() const
The size of the memory allocated, in bytes.
Definition: unique_ptr.h:666
Unique_ptr< T, A > & operator=(Unique_ptr< T, A > const &rhs)=delete
pointer clone() const
Clones the underlying memory and returns a pointer to the clone memory.
virtual ~Unique_ptr()
Destructor for the class.
Definition: unique_ptr.h:597
Unique_ptr< T, A > & reserve(size_t new_size)
Will resize the allocated memory to new_size.
reference operator[](size_t index) const
Subscript operator, to access an array element when T is of array type.
pointer get() const
Returns a pointer to the underlying allocated memory.
Definition: unique_ptr.h:660
memory::Ref_ptr< A > m_allocator
The allocator to be used to allocate memory.
Definition: unique_ptr.h:344
pointer operator->() const
Arrow operator to access the underlying object of type T.
A & allocator() const
Returns the used allocator instance, if any.
Definition: unique_ptr.h:710
Unique_ptr(Unique_ptr< T, A > const &rhs)=delete
Unique_ptr()
Default class constructor, only to be used with no specific allocator.
Definition: unique_ptr.h:547
size_t m_size
The size of the allocated memory.
Definition: unique_ptr.h:346
typename std::remove_extent< T >::type type
Definition: unique_ptr.h:154
void destroy()
Deallocates the underlying allocated memory.
Definition: unique_ptr.h:724
pointer m_underlying
The pointer to the underlying allocated memory
Definition: unique_ptr.h:342
type & reference
Definition: unique_ptr.h:156
pointer release()
Releases the ownership of the underlying allocated memory and returns a pointer to the beginning of t...
type * pointer
Definition: unique_ptr.h:155
reference operator*() const
Star operator to access the underlying object of type T.
Definition: unique_ptr.h:620
void reset()
Clears the underlying pointer and size.
Definition: unique_ptr.h:715
const char * p
Definition: ctype-mb.cc:1225
#define U
Definition: ctype-tis620.cc:74
#define ME_FATALERROR
Definition: my_sys.h:157
#define MY_WME
Definition: my_sys.h:128
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
#define MYF(v)
Definition: my_inttypes.h:97
void * my_malloc(PSI_memory_key key, size_t size, int flags)
Allocates size bytes of memory.
Definition: my_memory.cc:57
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
Common header for many mysys elements.
void copy(Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
Copy the counters, overwrite destination.
Definition: ut0counter.h:354
std::string HARNESS_EXPORT reset()
get 'reset attributes' ESC sequence.
Definition: vt100.cc:37
auto test_for_allocate(int T::*) -> decltype(std::declval< T >().allocate(std::declval< size_t >()), std::true_type{})
Tests for the existence of allocate(size_t) in order to disambiguate if T is an allocator class.
Definition: aligned_atomic.h:44
Unique_ptr< T, std::nullptr_t > make_unique(size_t size)
In-place constructs a new unique pointer with no specific allocator and with array type T.
size_t size(const char *const c)
Definition: base64.h:46
Definition: gcs_xcom_synode.h:64
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string type
Definition: replication_group_member_actions.proto:34
bool operator!=(const memory::PFS_allocator< T > &lhs, const memory::PFS_allocator< U > &rhs)
Definition: unique_ptr.h:454
bool operator==(const memory::PFS_allocator< T > &lhs, const memory::PFS_allocator< U > &rhs)
Definition: unique_ptr.h:448
Struct that allows for checking if T fulfills the Allocator named requirements.
Definition: unique_ptr.h:62
Definition: dtoa.cc:588
static ORDER * clone(THD *thd, ORDER *order)
Shallow clone the list of ORDER objects using mem_root and return the cloned list.
Definition: window.cc:85
int n
Definition: xcom_base.cc:509