From Jason Turner

[mem.res.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmprtp4w493/{from.md → to.md} +109 -0
tmp/tmprtp4w493/{from.md → to.md} RENAMED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class `memory_resource` <a id="mem.res.class">[[mem.res.class]]</a>
2
+
3
+ The `memory_resource` class is an abstract interface to an unbounded set
4
+ of classes encapsulating memory resources.
5
+
6
+ ``` cpp
7
+ class memory_resource {
8
+ static constexpr size_t max_align = alignof(max_align_t); // exposition only
9
+
10
+ public:
11
+ virtual ~memory_resource();
12
+
13
+ void* allocate(size_t bytes, size_t alignment = max_align);
14
+ void deallocate(void* p, size_t bytes, size_t alignment = max_align);
15
+
16
+ bool is_equal(const memory_resource& other) const noexcept;
17
+
18
+ private:
19
+ virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
20
+ virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
21
+
22
+ virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
23
+ };
24
+ ```
25
+
26
+ #### `memory_resource` public member functions <a id="mem.res.public">[[mem.res.public]]</a>
27
+
28
+ ``` cpp
29
+ ~memory_resource();
30
+ ```
31
+
32
+ *Effects:* Destroys this `memory_resource`.
33
+
34
+ ``` cpp
35
+ void* allocate(size_t bytes, size_t alignment = max_align);
36
+ ```
37
+
38
+ *Effects:* Equivalent to: `return do_allocate(bytes, alignment);`
39
+
40
+ ``` cpp
41
+ void deallocate(void* p, size_t bytes, size_t alignment = max_align);
42
+ ```
43
+
44
+ *Effects:* Equivalent to: `do_deallocate(p, bytes, alignment);`
45
+
46
+ ``` cpp
47
+ bool is_equal(const memory_resource& other) const noexcept;
48
+ ```
49
+
50
+ *Effects:* Equivalent to: `return do_is_equal(other);`
51
+
52
+ #### `memory_resource` private virtual member functions <a id="mem.res.private">[[mem.res.private]]</a>
53
+
54
+ ``` cpp
55
+ virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
56
+ ```
57
+
58
+ *Requires:* `alignment` shall be a power of two.
59
+
60
+ *Returns:* A derived class shall implement this function to return a
61
+ pointer to allocated storage ([[basic.stc.dynamic.deallocation]]) with
62
+ a size of at least `bytes`. The returned storage is aligned to the
63
+ specified alignment, if such alignment is supported ([[basic.align]]);
64
+ otherwise it is aligned to `max_align`.
65
+
66
+ *Throws:* A derived class implementation shall throw an appropriate
67
+ exception if it is unable to allocate memory with the requested size and
68
+ alignment.
69
+
70
+ ``` cpp
71
+ virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
72
+ ```
73
+
74
+ *Requires:* `p` shall have been returned from a prior call to
75
+ `allocate(bytes, alignment)` on a memory resource equal to `*this`, and
76
+ the storage at `p` shall not yet have been deallocated.
77
+
78
+ *Effects:* A derived class shall implement this function to dispose of
79
+ allocated storage.
80
+
81
+ *Throws:* Nothing.
82
+
83
+ ``` cpp
84
+ virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
85
+ ```
86
+
87
+ *Returns:* A derived class shall implement this function to return
88
+ `true` if memory allocated from `this` can be deallocated from `other`
89
+ and vice-versa, otherwise `false`.
90
+
91
+ [*Note 1*: The most-derived type of `other` might not match the type of
92
+ `this`. For a derived class `D`, a typical implementation of this
93
+ function will immediately return `false` if
94
+ `dynamic_cast<const D*>(&other) == nullptr`. — *end note*]
95
+
96
+ #### `memory_resource` equality <a id="mem.res.eq">[[mem.res.eq]]</a>
97
+
98
+ ``` cpp
99
+ bool operator==(const memory_resource& a, const memory_resource& b) noexcept;
100
+ ```
101
+
102
+ *Returns:* `&a == &b || a.is_equal(b)`.
103
+
104
+ ``` cpp
105
+ bool operator!=(const memory_resource& a, const memory_resource& b) noexcept;
106
+ ```
107
+
108
+ *Returns:* `!(a == b)`.
109
+