[mem.res.monotonic.buffer.mem] (original) (raw)

20 Memory management library [mem]

20.5 Memory resources [mem.res]

20.5.6 Class monotonic_buffer_resource [mem.res.monotonic.buffer]

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

Effects: Calls upstream_rsrc->deallocate() as necessary to release all allocated memory.

Resets current_buffer and next_buffer_sizeto their initial values at construction.

[Note 1:

The memory is released back to upstream_rsrceven if some blocks that were allocated from *thishave not been deallocated from *this.

— _end note_]

memory_resource* upstream_resource() const;

Returns: The value of upstream_rsrc.

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

Effects: If the unused space in current_buffercan 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_sizeby an implementation-defined growth factor (which need not be integral), then allocate the return block from the newly-allocated current_buffer.

The size and alignment of the allocated memory shall meet the requirements for a class derived from memory_resource ([mem.res.class]).

Throws: Nothing unless upstream_rsrc->allocate() throws.

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

Remarks: Memory used by this resource increases monotonically until its destruction.

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