[#PoolResource]
= PoolResource
:mrdocs:

A memory resource similar to std&colon;&colon;pmr&colon;&colon;unsynchronized&lowbar;pool&lowbar;resource, but optimized for node&hyphen;based containers&period; It has the following properties&colon;

== Synopsis

Declared in `&lt;support&sol;allocators&sol;pool&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    std::size&lowbar;t MAX&lowbar;BLOCK&lowbar;SIZE&lowbar;BYTES,
    std::size&lowbar;t ALIGN&lowbar;BYTES&gt;
class PoolResource final
----

== Description

&ast; Owns the allocated memory and frees it on destruction, even when deallocate has not been called on the allocated blocks&period;

&ast; Consists of a number of pools, each one for a different block size&period; Each pool holds blocks of uniform size in a freelist&period;

&ast; Exhausting memory in a freelist causes a new allocation of a fixed size chunk&period; This chunk is used to carve out blocks&period;

&ast; Block sizes or alignments that can not be served by the pools are allocated and deallocated by operator new()&period;

PoolResource is not thread&hyphen;safe&period; It is intended to be used by PoolAllocator&period;

An example&colon; If you create a PoolResource&lt;128, 8&gt;(262144) and perform a bunch of allocations and deallocate 2 blocks with size 8 bytes, and 3 blocks with size 16, the members will look like this&colon;

m&lowbar;free&lowbar;lists m&lowbar;allocated&lowbar;chunks ┌───┐ ┌───┐ ┌────────────&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;──────┐ │ │ blocks │ ├─►│ 262144 B │ │ │ ┌─────┐ ┌─────┐ └─┬─┘ └────────────&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;──────┘ │ 1 ├─►│ 8 B ├─►│ 8 B │ │ │ │ └─────┘ └─────┘ &colon; │ │ │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ ▼ │ 2 ├─►│16 B ├─►│16 B ├─►│16 B │ ┌───┐ ┌─────────────────────────┐ │ │ └─────┘ └─────┘ └─────┘ │ ├─►│ ▲ │ ▲ │ │ └───┘ └──────────┬──────────────┘ │ │ &period; │ │ m&lowbar;available&lowbar;memory&lowbar;end │ &period; │ m&lowbar;available&lowbar;memory&lowbar;it │ &period; │ │ │ │ │ │16 │ └───┘

Here m&lowbar;free&lowbar;lists&lsqb;1&rsqb;holds the 2 blocks of size 8 bytes, and m&lowbar;free&lowbar;lists&lsqb;2&rsqb; holds the 3 blocks of size 16&period; The blocks came from the data stored in the m&lowbar;allocated&lowbar;chunks list&period; Each chunk has bytes 262144&period; The last chunk has still some memory available for the blocks, and when m&lowbar;available&lowbar;memory&lowbar;it is at the end, a new chunk will be allocated and added to the list&period;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:PoolResource/2constructor-01.adoc[`PoolResource`]         [.small]#[constructor]#
| Constructors
| xref:PoolResource/2destructor.adoc[`&#126;PoolResource`] [.small]#[destructor]#
| Deallocates all memory allocated associated with the memory resource&period;
| xref:PoolResource/operator_assign-05c.adoc[`operator&equals;`] 
| Assignment operators
| xref:PoolResource/Allocate.adoc[`Allocate`] 
| Allocates a block of bytes&period; If possible the freelist is used, otherwise allocation is forwarded to &colon;&colon;operator new()&period;
| xref:PoolResource/ChunkSizeBytes.adoc[`ChunkSizeBytes`] 
| Size in bytes to allocate per chunk, currently hardcoded to a fixed size&period;
| xref:PoolResource/Deallocate.adoc[`Deallocate`] 
| Returns a block to the freelists, or deletes the block when it did not come from the chunks&period;
| xref:PoolResource/NumAllocatedChunks.adoc[`NumAllocatedChunks`] 
| Number of allocated chunks
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:PoolResourceTester.adoc[PoolResourceTester]`
| Access to internals for testing purpose only
|===

== Template Parameters

[cols="1,4"]
|===
| Name| Description
| *MAX&lowbar;BLOCK&lowbar;SIZE&lowbar;BYTES*
| Maximum size to allocate with the pool&period; If larger sizes are requested, allocation falls back to new()&period;
| *ALIGN&lowbar;BYTES*
| Required alignment for the allocations&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
