libstdc++
std::pmr::monotonic_buffer_resource Class Reference

#include <memory_resource>

Inheritance diagram for std::pmr::monotonic_buffer_resource:
[legend]

Public Member Functions

 monotonic_buffer_resource (const monotonic_buffer_resource &)=delete
 
 monotonic_buffer_resource (memory_resource *__upstream) noexcept
 
 monotonic_buffer_resource (size_t __initial_size) noexcept
 
 monotonic_buffer_resource (size_t __initial_size, memory_resource *__upstream) noexcept
 
 monotonic_buffer_resource (void *__buffer, size_t __buffer_size) noexcept
 
 monotonic_buffer_resource (void *__buffer, size_t __buffer_size, memory_resource *__upstream) noexcept
 
voidallocate (size_t __bytes, size_t __alignment=_S_max_align)
 
void deallocate (void *__p, size_t __bytes, size_t __alignment=_S_max_align)
 
bool is_equal (const memory_resource &__other) const noexcept
 
monotonic_buffer_resourceoperator= (const monotonic_buffer_resource &)=delete
 
void release () noexcept
 
memory_resourceupstream_resource () const noexcept
 

Protected Member Functions

voiddo_allocate (size_t __bytes, size_t __alignment) override
 
void do_deallocate (void *, size_t, size_t) override
 
bool do_is_equal (const memory_resource &__other) const noexcept override
 

Detailed Description

A memory resource that allocates from a fixed-size buffer.

The main feature of a pmr::monotonic_buffer_resource is that its do_deallocate does nothing. This makes it very fast because there is no need to manage a free list, and every allocation simply returns a new block of memory, rather than searching for a suitably-sized free block. Because deallocating is a no-op, the amount of memory used by the resource only grows until release() (or the destructor) is called to return all memory to upstream.

A monotonic_buffer_resource can be initialized with a buffer that will be used to satisfy all allocation requests, until the buffer is full. After that a new buffer will be allocated from the upstream resource. By using a stack buffer and pmr::null_memory_resource() as the upstream you can get a memory resource that only uses the stack and never dynamically allocates.

Since
C++17

Definition at line 337 of file memory_resource.

Constructor & Destructor Documentation

◆ monotonic_buffer_resource() [1/6]

std::pmr::monotonic_buffer_resource::monotonic_buffer_resource ( memory_resource __upstream)
inlineexplicitnoexcept

Definition at line 341 of file memory_resource.

◆ monotonic_buffer_resource() [2/6]

std::pmr::monotonic_buffer_resource::monotonic_buffer_resource ( size_t  __initial_size,
memory_resource __upstream 
)
inlinenoexcept

Definition at line 346 of file memory_resource.

◆ monotonic_buffer_resource() [3/6]

std::pmr::monotonic_buffer_resource::monotonic_buffer_resource ( void __buffer,
size_t  __buffer_size,
memory_resource __upstream 
)
inlinenoexcept

Definition at line 356 of file memory_resource.

◆ monotonic_buffer_resource() [4/6]

std::pmr::monotonic_buffer_resource::monotonic_buffer_resource ( )
inlinenoexcept

Definition at line 368 of file memory_resource.

◆ monotonic_buffer_resource() [5/6]

std::pmr::monotonic_buffer_resource::monotonic_buffer_resource ( size_t  __initial_size)
inlineexplicitnoexcept

Definition at line 373 of file memory_resource.

◆ monotonic_buffer_resource() [6/6]

std::pmr::monotonic_buffer_resource::monotonic_buffer_resource ( void __buffer,
size_t  __buffer_size 
)
inlinenoexcept

Definition at line 377 of file memory_resource.

Member Function Documentation

◆ allocate()

void * std::pmr::memory_resource::allocate ( size_t  __bytes,
size_t  __alignment = _S_max_align 
)
inlineinherited

Definition at line 74 of file memory_resource.h.

◆ deallocate()

void std::pmr::memory_resource::deallocate ( void __p,
size_t  __bytes,
size_t  __alignment = _S_max_align 
)
inlineinherited

Definition at line 79 of file memory_resource.h.

◆ do_allocate()

void * std::pmr::monotonic_buffer_resource::do_allocate ( size_t  __bytes,
size_t  __alignment 
)
inlineoverrideprotectedvirtual

Implements std::pmr::memory_resource.

Definition at line 414 of file memory_resource.

◆ do_deallocate()

void std::pmr::monotonic_buffer_resource::do_deallocate ( void ,
size_t  ,
size_t   
)
inlineoverrideprotectedvirtual

Implements std::pmr::memory_resource.

Definition at line 431 of file memory_resource.

◆ do_is_equal()

bool std::pmr::monotonic_buffer_resource::do_is_equal ( const memory_resource __other) const
inlineoverrideprotectedvirtualnoexcept

Implements std::pmr::memory_resource.

Definition at line 435 of file memory_resource.

◆ is_equal()

bool std::pmr::memory_resource::is_equal ( const memory_resource __other) const
inlinenoexceptinherited

Definition at line 85 of file memory_resource.h.

◆ release()

void std::pmr::monotonic_buffer_resource::release ( )
inlinenoexcept

Definition at line 389 of file memory_resource.

◆ upstream_resource()

memory_resource * std::pmr::monotonic_buffer_resource::upstream_resource ( ) const
inlinenoexcept

Definition at line 408 of file memory_resource.


The documentation for this class was generated from the following file: