Difference between revisions of "cpp/memory/unsynchronized pool resource"
From cppreference.com
m (typo) |
Andreas Krug (Talk | contribs) m (fmt) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{cpp/memory/pmr/title|unsynchronized_pool_resource}} | {{cpp/memory/pmr/title|unsynchronized_pool_resource}} | ||
{{cpp/memory/unsynchronized_pool_resource/navbar}} | {{cpp/memory/unsynchronized_pool_resource/navbar}} | ||
− | {{ddcl|header=memory_resource | since=c++17| | + | {{ddcl|header=memory_resource|since=c++17| |
class unsynchronized_pool_resource : public std::pmr::memory_resource; | class unsynchronized_pool_resource : public std::pmr::memory_resource; | ||
}} | }} | ||
Line 7: | Line 7: | ||
The class {{tt|std::pmr::unsynchronized_pool_resource}} is a general-purpose memory resource class with the following properties: | The class {{tt|std::pmr::unsynchronized_pool_resource}} is a general-purpose memory resource class with the following properties: | ||
* It owns the allocated memory and frees it on destruction, even if {{tt|deallocate}} has not been called for some of the allocated blocks. | * It owns the allocated memory and frees it on destruction, even if {{tt|deallocate}} has not been called for some of the allocated blocks. | ||
− | * It consists of a collection of ''pools'' that serves requests for different block sizes. Each pool manages a collection of ''chunks'' that are then divided into blocks of uniform size. | + | * It consists of a collection of ''pools'' that serves requests for different block sizes. Each pool manages a collection of ''chunks'' that are then divided into blocks of uniform size. |
* Calls to {{ltt|cpp/memory/unsynchronized_pool_resource/do_allocate}} are dispatched to the pool serving the smallest blocks accommodating the requested size. | * Calls to {{ltt|cpp/memory/unsynchronized_pool_resource/do_allocate}} are dispatched to the pool serving the smallest blocks accommodating the requested size. | ||
* Exhausting memory in the pool causes the next allocation request for that pool to allocate an additional chunk of memory from the ''upstream allocator'' to replenish the pool. The chunk size obtained increases geometrically. | * Exhausting memory in the pool causes the next allocation request for that pool to allocate an additional chunk of memory from the ''upstream allocator'' to replenish the pool. The chunk size obtained increases geometrically. | ||
Line 17: | Line 17: | ||
===Member functions=== | ===Member functions=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc constructor}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc constructor}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc destructor}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc destructor}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc operator{{=}}}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc operator{{=}}}} |
− | {{dsc h2 | Public member functions}} | + | {{dsc h2|Public member functions}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc release}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc release}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc upstream_resource}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc upstream_resource}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc options}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc options}} |
− | {{dsc h2 | Protected member functions}} | + | {{dsc h2|Protected member functions}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc do_allocate}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc do_allocate}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc do_deallocate}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc do_deallocate}} |
− | {{dsc inc | cpp/memory/unsynchronized_pool_resource/dsc do_is_equal}} | + | {{dsc inc|cpp/memory/unsynchronized_pool_resource/dsc do_is_equal}} |
{{dsc end}} | {{dsc end}} | ||
− | {{langlinks|ja|zh}} | + | {{langlinks|es|ja|ru|zh}} |
Latest revision as of 07:43, 18 December 2023
Defined in header <memory_resource>
|
||
class unsynchronized_pool_resource : public std::pmr::memory_resource; |
(since C++17) | |
The class std::pmr::unsynchronized_pool_resource
is a general-purpose memory resource class with the following properties:
- It owns the allocated memory and frees it on destruction, even if
deallocate
has not been called for some of the allocated blocks. - It consists of a collection of pools that serves requests for different block sizes. Each pool manages a collection of chunks that are then divided into blocks of uniform size.
- Calls to do_allocate are dispatched to the pool serving the smallest blocks accommodating the requested size.
- Exhausting memory in the pool causes the next allocation request for that pool to allocate an additional chunk of memory from the upstream allocator to replenish the pool. The chunk size obtained increases geometrically.
- Allocations requests that exceed the largest block size are served from the upstream allocator directly.
- The largest block size and maximum chunk size may be tuned by passing a std::pmr::pool_options struct to its constructor.
unsynchronized_pool_resource
is not thread-safe, and cannot be accessed from multiple threads simultaneously; use synchronized_pool_resource if access from multiple threads is required.
[edit] Member functions
constructs an unsynchronized_pool_resource (public member function) | |
[virtual] |
destroys an unsynchronized_pool_resource , releasing all allocated memory (virtual public member function) |
operator= [deleted] |
copy assignment operator is deleted. unsynchronized_pool_resource is not copy assignable (public member function) |
Public member functions | |
release all allocated memory (public member function) | |
returns a pointer to the upstream memory resource (public member function) | |
returns the options that control the pooling behavior of this resource (public member function) | |
Protected member functions | |
[virtual] |
allocate memory (virtual protected member function) |
[virtual] |
return memory to the pool (virtual protected member function) |
[virtual] |
compare for equality with another std::pmr::memory_resource (virtual protected member function) |