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