tmp/tmp3x9qts_k/{from.md → to.md}
RENAMED
|
@@ -1,25 +1,13 @@
|
|
| 1 |
### Class `monotonic_buffer_resource` <a id="mem.res.monotonic.buffer">[[mem.res.monotonic.buffer]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
A `monotonic_buffer_resource` is a special-purpose memory resource
|
| 4 |
intended for very fast memory allocations in situations where memory is
|
| 5 |
used to build up a few objects and then is released all at once when the
|
| 6 |
-
memory resource object is destroyed.
|
| 7 |
-
|
| 8 |
-
- A call to `deallocate` has no effect, thus the amount of memory
|
| 9 |
-
consumed increases monotonically until the resource is destroyed.
|
| 10 |
-
- The program can supply an initial buffer, which the allocator uses to
|
| 11 |
-
satisfy memory requests.
|
| 12 |
-
- When the initial buffer (if any) is exhausted, it obtains additional
|
| 13 |
-
buffers from an *upstream* memory resource supplied at construction.
|
| 14 |
-
Each additional buffer is larger than the previous one, following a
|
| 15 |
-
geometric progression.
|
| 16 |
-
- It is intended for access from one thread of control at a time.
|
| 17 |
-
Specifically, calls to `allocate` and `deallocate` do not synchronize
|
| 18 |
-
with one another.
|
| 19 |
-
- It frees the allocated memory on destruction, even if `deallocate` has
|
| 20 |
-
not been called for some of the allocated blocks.
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
namespace std::pmr {
|
| 24 |
class monotonic_buffer_resource : public memory_resource {
|
| 25 |
memory_resource* upstream_rsrc; // exposition only
|
|
@@ -94,11 +82,12 @@ factor (which need not be integral).
|
|
| 94 |
``` cpp
|
| 95 |
void release();
|
| 96 |
```
|
| 97 |
|
| 98 |
*Effects:* Calls `upstream_rsrc->deallocate()` as necessary to release
|
| 99 |
-
all allocated memory.
|
|
|
|
| 100 |
|
| 101 |
[*Note 1*: The memory is released back to `upstream_rsrc` even if some
|
| 102 |
blocks that were allocated from `this` have not been deallocated from
|
| 103 |
`this`. — *end note*]
|
| 104 |
|
|
@@ -110,25 +99,25 @@ memory_resource* upstream_resource() const;
|
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 113 |
```
|
| 114 |
|
| 115 |
-
*Returns:* A pointer to allocated
|
| 116 |
-
storage [[basic.stc.dynamic.allocation]] with a size of at least
|
| 117 |
-
`bytes`. The size and alignment of the allocated memory shall meet the
|
| 118 |
-
requirements for a class derived from `memory_resource`
|
| 119 |
-
[[mem.res.class]].
|
| 120 |
-
|
| 121 |
*Effects:* If the unused space in `current_buffer` can fit a block with
|
| 122 |
the specified `bytes` and `alignment`, then allocate the return block
|
| 123 |
from `current_buffer`; otherwise set `current_buffer` to
|
| 124 |
`upstream_rsrc->allocate(n, m)`, where `n` is not less than
|
| 125 |
`max(bytes, next_buffer_size)` and `m` is not less than `alignment`, and
|
| 126 |
increase `next_buffer_size` by an *implementation-defined* growth factor
|
| 127 |
(which need not be integral), then allocate the return block from the
|
| 128 |
newly-allocated `current_buffer`.
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
*Throws:* Nothing unless `upstream_rsrc->allocate()` throws.
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 134 |
```
|
|
|
|
| 1 |
### Class `monotonic_buffer_resource` <a id="mem.res.monotonic.buffer">[[mem.res.monotonic.buffer]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="mem.res.monotonic.buffer.general">[[mem.res.monotonic.buffer.general]]</a>
|
| 4 |
+
|
| 5 |
A `monotonic_buffer_resource` is a special-purpose memory resource
|
| 6 |
intended for very fast memory allocations in situations where memory is
|
| 7 |
used to build up a few objects and then is released all at once when the
|
| 8 |
+
memory resource object is destroyed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
``` cpp
|
| 11 |
namespace std::pmr {
|
| 12 |
class monotonic_buffer_resource : public memory_resource {
|
| 13 |
memory_resource* upstream_rsrc; // exposition only
|
|
|
|
| 82 |
``` cpp
|
| 83 |
void release();
|
| 84 |
```
|
| 85 |
|
| 86 |
*Effects:* Calls `upstream_rsrc->deallocate()` as necessary to release
|
| 87 |
+
all allocated memory. Resets `current_buffer` and `next_buffer_size` to
|
| 88 |
+
their initial values at construction.
|
| 89 |
|
| 90 |
[*Note 1*: The memory is released back to `upstream_rsrc` even if some
|
| 91 |
blocks that were allocated from `this` have not been deallocated from
|
| 92 |
`this`. — *end note*]
|
| 93 |
|
|
|
|
| 99 |
|
| 100 |
``` cpp
|
| 101 |
void* do_allocate(size_t bytes, size_t alignment) override;
|
| 102 |
```
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
*Effects:* If the unused space in `current_buffer` can fit a block with
|
| 105 |
the specified `bytes` and `alignment`, then allocate the return block
|
| 106 |
from `current_buffer`; otherwise set `current_buffer` to
|
| 107 |
`upstream_rsrc->allocate(n, m)`, where `n` is not less than
|
| 108 |
`max(bytes, next_buffer_size)` and `m` is not less than `alignment`, and
|
| 109 |
increase `next_buffer_size` by an *implementation-defined* growth factor
|
| 110 |
(which need not be integral), then allocate the return block from the
|
| 111 |
newly-allocated `current_buffer`.
|
| 112 |
|
| 113 |
+
*Returns:* A pointer to allocated
|
| 114 |
+
storage [[basic.stc.dynamic.allocation]] with a size of at least
|
| 115 |
+
`bytes`. The size and alignment of the allocated memory shall meet the
|
| 116 |
+
requirements for a class derived from `memory_resource`
|
| 117 |
+
[[mem.res.class]].
|
| 118 |
+
|
| 119 |
*Throws:* Nothing unless `upstream_rsrc->allocate()` throws.
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
|
| 123 |
```
|