MySQL 9.0.0
Source Code Documentation
pfs_std_allocator.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 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 PFS_STD_ALLOCATOR_H
25#define PFS_STD_ALLOCATOR_H
26
27#include "my_config.h"
28
29#include <memory>
30
31#include "my_compiler.h"
32#include "my_inttypes.h"
34
36
37template <class T>
39 public:
40 typedef T value_type;
41
43 : m_klass(klass) {}
44
45 template <class U>
46 constexpr explicit PFS_std_allocator(const PFS_std_allocator<U> &u) noexcept
47 : m_klass(u.get_class()) {}
48
49 [[nodiscard]] T *allocate(std::size_t n) {
50 if (n > std::numeric_limits<std::size_t>::max() / sizeof(T))
51 throw std::bad_array_new_length();
52
53 const size_t size = n * sizeof(T);
54 void *mem = pfs_malloc(m_klass, size, MYF(0));
55 if (mem == nullptr) {
56 throw std::bad_alloc();
57 }
58 return static_cast<T *>(mem);
59 }
60
61 void deallocate(T *p, std::size_t n) noexcept {
62 const size_t size = n * sizeof(T);
64 }
65
67
68 private:
70};
71
72template <class T, class U>
74 return (t.m_klass == u.m_klass);
75}
76
77template <class T, class U>
79 return (t.m_klass != u.m_klass);
80}
81
82#endif
const char * p
Definition: ctype-mb.cc:1225
Header for compiler-dependent features.
Some integer typedefs for easier portability.
#define MYF(v)
Definition: my_inttypes.h:97
size_t size(const char *const c)
Definition: base64.h:46
void * pfs_malloc(PFS_builtin_memory_class *klass, size_t size, myf flags)
Memory allocation for the performance schema.
Definition: pfs_global.cc:61
void pfs_free(PFS_builtin_memory_class *klass, size_t size, void *ptr)
Free memory allocated with.
Definition: pfs_global.cc:108
Miscellaneous global dependencies (declarations).
bool operator==(const PFS_std_allocator< T > &t, const PFS_std_allocator< U > &u)
Definition: pfs_std_allocator.h:73
bool operator!=(const PFS_std_allocator< T > &t, const PFS_std_allocator< U > &u)
Definition: pfs_std_allocator.h:78
static MEM_ROOT mem
Definition: sql_servers.cc:100
Definition: pfs_builtin_memory.h:39
Definition: pfs_std_allocator.h:38
PFS_builtin_memory_class * m_klass
Definition: pfs_std_allocator.h:69
PFS_std_allocator(PFS_builtin_memory_class *klass)
Definition: pfs_std_allocator.h:42
void deallocate(T *p, std::size_t n) noexcept
Definition: pfs_std_allocator.h:61
T value_type
Definition: pfs_std_allocator.h:40
PFS_builtin_memory_class * get_class() const
Definition: pfs_std_allocator.h:66
T * allocate(std::size_t n)
Definition: pfs_std_allocator.h:49
constexpr PFS_std_allocator(const PFS_std_allocator< U > &u) noexcept
Definition: pfs_std_allocator.h:46
int n
Definition: xcom_base.cc:509