Pool memory resource.
More...
#include <playrho/pmr/PoolMemoryResource.hpp>
|
| static std::size_t | GetMaxNumBytes () noexcept |
| | Gets the maximum number of bytes supported for any allocations this class does. More...
|
| |
Pool memory resource.
- Note
- This is a memory pooling implementation of a
memory_resource. It is similar to std::pmr::unsynchronized_pool_resource.
- See also
- https://en.cppreference.com/w/cpp/memory/unsynchronized_pool_resource
◆ PoolMemoryResource() [1/2]
Default and initializing constructor.
- Note
- Constructs an instance with the given options such that
options.reserveBuffers buffers are pre-allocated with options.reserveBytes bytes and are immediately available for do_allocate calls.
- Precondition
- Upstream memory resource won't throw any exceptions if called to deallocate buffers it's previously allocated.
- Postcondition
GetOptions() returns the given options.
- Exceptions
-
| std::length_error | if options.reserveBuffers > options.limitBuffers. |
| std::bad_array_new_length | if options.reserveBytes > GetMaxNumBytes(). |
| std::bad_alloc | if an allocation of options.reserveBytes fails for any of the options.reserveBuffers buffers. |
◆ PoolMemoryResource() [2/2]
| playrho::pmr::PoolMemoryResource::PoolMemoryResource |
( |
memory_resource * |
upstream | ) |
|
|
inline |
Upstream initializing constructor.
- Precondition
- Upstream memory resource won't throw any exceptions if called to deallocate buffers it's previously allocated.
◆ ~PoolMemoryResource()
| playrho::pmr::PoolMemoryResource::~PoolMemoryResource |
( |
| ) |
|
|
overridenoexcept |
Destructor.
- Note
- Deallocates the allocated memory.
- Warning
- Terminates if upstream resource throws on deallocating any memory.
◆ do_allocate()
| void * playrho::pmr::PoolMemoryResource::do_allocate |
( |
std::size_t |
num_bytes, |
|
|
std::size_t |
alignment |
|
) |
| |
|
overridevirtual |
Do the requested allocation.
- Note
- Setting
Options::limitBuffers to 1 can help identify code that's not reserving enough capacity ahead of time to avoid having to move data over to new buffers whenever existing capacity runs out by causing std::length to get thrown then instead.
-
This function provides the strong exception guarantee. The state of the instance will be unchanged if an exception is thrown.
- Exceptions
-
| std::bad_array_new_length | if num_bytes is greater than GetMaxNumBytes(). |
| std::length_error | If called with no deallocated buffers available and the number of allocated buffers has reached (or exceeded) Options::limitBuffers. |
Implements playrho::pmr::memory_resource.
◆ do_is_equal()
| bool playrho::pmr::PoolMemoryResource::do_is_equal |
( |
const memory_resource & |
other | ) |
const |
|
overridevirtualnoexcept |
Do an equality comparison with the given instance.
- Returns
true if the address of the other instance is the same as the address of this instance, false otherwise.
Implements playrho::pmr::memory_resource.
◆ GetMaxNumBytes()
| std::size_t playrho::pmr::PoolMemoryResource::GetMaxNumBytes |
( |
| ) |
|
|
staticnoexcept |
Gets the maximum number of bytes supported for any allocations this class does.
- See also
- PoolMemoryResource(const Options& options), do_allocate.
Referenced by do_allocate().
◆ GetOptions()
Gets the options used by this instance.
- See also
- PoolMemoryResource(const Options&, memory_resource*).
The documentation for this class was generated from the following files:
- Library/include/playrho/pmr/PoolMemoryResource.hpp
- Library/source/playrho/pmr/PoolMemoryResource.cpp