[mem.res.monotonic.buffer.mem]

# 20 Memory management library [[mem]](./#mem)

## 20.5 Memory resources [[mem.res]](mem.res#monotonic.buffer.mem)

### 20.5.6 Class monotonic_buffer_resource [[mem.res.monotonic.buffer]](mem.res.monotonic.buffer#mem)

#### 20.5.6.3 Members [mem.res.monotonic.buffer.mem]

[ð](#lib:release,monotonic_buffer_resource)

`void release();
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8503)

*Effects*: Calls upstream_rsrc->deallocate() as necessary
to release all allocated memory[.](#1.sentence-1)

Resets current_buffer and next_buffer_size to their initial values at construction[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8510)

[*Note [1](#note-1)*:

The memory is released back to upstream_rsrc even if some blocks that were allocated from *this have not been deallocated from *this[.](#2.sentence-1)

â *end note*]

[ð](#lib:upstream_resource,monotonic_buffer_resource)

`memory_resource* upstream_resource() const;
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8524)

*Returns*: The value of upstream_rsrc[.](#3.sentence-1)

[ð](#lib:do_allocate,monotonic_buffer_resource)

`void* do_allocate(size_t bytes, size_t alignment) override;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8535)

*Effects*: If the unused space in current_buffer can fit a block with the specified bytes and alignment,
then allocate the return block from current_buffer;
otherwise set current_buffer to upstream_rsrc->allocate(n, m),
where n is not less than max(bytes, next_buffer_size) andm is not less than alignment,
and increase next_buffer_size by an implementation-defined growth factor (which need not be integral),
then allocate the return block from the newly-allocated current_buffer[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8547)

*Returns*: A pointer to allocated storage ([[basic.stc.dynamic.allocation]](basic.stc.dynamic.allocation "6.8.6.5.2 Allocation functions"))
with a size of at least bytes[.](#5.sentence-1)

The size and alignment of the allocated memory shall meet the requirements
for a class derived from memory_resource ([[mem.res.class]](mem.res.class "20.5.2 Class memory_­resource"))[.](#5.sentence-2)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8554)

*Throws*: Nothing unless upstream_rsrc->allocate() throws[.](#6.sentence-1)

[ð](#lib:do_deallocate,monotonic_buffer_resource)

`void do_deallocate(void* p, size_t bytes, size_t alignment) override;
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8565)

*Effects*: None[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8569)

*Throws*: Nothing[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8573)

*Remarks*: Memory used by this resource increases monotonically until its destruction[.](#9.sentence-1)

[ð](#lib:do_is_equal,monotonic_buffer_resource)

`bool do_is_equal(const memory_resource& other) const noexcept override;
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8584)

*Returns*: this == &other[.](#10.sentence-1)
