![]() |
Home | Libraries | People | FAQ | More |
boost::container::pmr::monotonic_buffer_resource
// In header: <boost/container/pmr/monotonic_buffer_resource.hpp> class monotonic_buffer_resource : public { public: // construct/copy/destruct (memory_resource * = ) ; (, memory_resource * = ) ; (void *, , memory_resource * = ) ; (const monotonic_buffer_resource &) = ; monotonic_buffer_resource (const monotonic_buffer_resource &) = ; ~(); // public member functions void () ; memory_resource * () ; (, ) ; ( = u) ; const void * () ; () ; // protected member functions void * (, ); void (void *, , ) ; bool (const memory_resource &) ; // public data members static const ; };
A monotonic_buffer_resource is a special-purpose memory resource intended for very fast memory allocations in situations where memory is used to build up a few objects and then is released all at once when the memory resource object is destroyed. It has the following qualities:
A call to deallocate has no effect, thus the amount of memory consumed increases monotonically until the resource is destroyed.
The program can supply an initial buffer, which the allocator uses to satisfy memory requests.
When the initial buffer (if any) is exhausted, it obtains additional buffers from an upstream memory resource supplied at construction. Each additional buffer is larger than the previous one, following a geometric progression.
It is intended for access from one thread of control at a time. Specifically, calls to allocate and deallocate do not synchronize with one another.
It owns the allocated memory and frees it on destruction, even if deallocate has not been called for some of the allocated blocks.
monotonic_buffer_resource
public
construct/copy/destruct(memory_resource * upstream = ) ;
Requires: upstream
shall be the address of a valid memory resource or nullptr
Effects: If upstream
is not nullptr, sets the internal resource to upstream
, to get_default_resource() otherwise. Sets the internal current_buffer
to nullptr
and the internal next_buffer_size
to an implementation-defined size.
( initial_size, memory_resource * upstream = ) ;
Requires: upstream
shall be the address of a valid memory resource or nullptr
and initial_size
shall be greater than zero.
Effects: If upstream
is not nullptr, sets the internal resource to upstream
, to get_default_resource() otherwise. Sets the internal current_buffer
to nullptr
and next_buffer_size
to at least initial_size
.
(void * buffer, buffer_size, memory_resource * upstream = ) ;
Requires: upstream
shall be the address of a valid memory resource or nullptr
, buffer_size
shall be no larger than the number of bytes in buffer.
Effects: If upstream
is not nullptr, sets the internal resource to upstream
, to get_default_resource() otherwise. Sets the internal current_buffer
to buffer
, and next_buffer_size
to buffer_size
(but not less than an implementation-defined size), then increases next_buffer_size
by an implementation-defined growth factor (which need not be integral).
(const monotonic_buffer_resource &) = ;
monotonic_buffer_resource (const monotonic_buffer_resource &) = ;
~();
Effects: Calls this->release()
.
monotonic_buffer_resource
public member functionsvoid () ;
Effects: upstream_resource()->deallocate()
as necessary to release all allocated memory. [Note: memory is released back to upstream_resource()
even if some blocks that were allocated from this have not been deallocated from this. - end note]
memory_resource * () ;
Returns: The value of the internal resource.
( alignment, wasted_due_to_alignment) ;
Returns: The number of bytes of storage available for the specified alignment and the number of bytes wasted due to the requested alignment.
Note: Non-standard extension.
( alignment = u) ;
Returns: The number of bytes of storage available for the specified alignment.
Note: Non-standard extension.
const void * () ;
Returns: The address pointing to the start of the current free storage.
Note: Non-standard extension.
() ;
Returns: The number of bytes that will be requested for the next buffer once the current one is exhausted.
Note: Non-standard extension.
monotonic_buffer_resource
protected member functionsvoid * ( bytes, alignment);
Returns: A pointer to allocated storage with a size of at least bytes
. The size and alignment of the allocated memory shall meet the requirements for a class derived from
.memory_resource
Effects: If the unused space in the internal current_buffer
can fit a block with the specified bytes and alignment, then allocate the return block from the internal current_buffer
; otherwise sets the internal current_buffer
to upstream_resource()->allocate(n, m)
, where n
is not less than max(bytes, next_buffer_size)
and m
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 internal current_buffer
.
Throws: Nothing unless upstream_resource()->allocate()
throws.
void (void * p, bytes, alignment) ;
Effects: None
Throws: Nothing
Remarks: Memory used by this resource increases monotonically until its destruction.
bool (const memory_resource & other) ;
Returns: this == dynamic_cast<const monotonic_buffer_resource*>(&other)
.