Module radiorust::bufferpool

source ·
Expand description

Pools allowing to get buffers that are recycled when dropped

Most blocks will produce and/or consume Chunk<T>s. To create such Chunks, you should first create a ChunkBufPool<T> from which you can obtain a ChunkBuf<T>, which can be treated and filled like a Vec<T>. When all data has been added to the ChunkBuf<T>, it can be finalized and thus converted into a Chunk<T>.

Because it’s inefficient to always allocate new Vecs when a new chunk of data is prepared, this module provides a way to “recycle” the underlying Vec of a Chunk. This works by counting clones of the Chunk (or parts thereof) through an internal Arc and sending the Vec back to the originating pool (ChunkBufPool) when the last clone is dropped.

See ChunkBufPool for an example.

Chunk<T>s may also be created by directly converting a Vec<T> into a Chunk<T> (using From or Into). The created Chunk<T> is then non-recyclable. This can be used where only a single Chunk<T> is needed and recycling doesn’t give any advantages.

Structs

Buffer for reading that gets recycled when dropped
Buffer for writing that can be converted into a cheaply cloneable Chunk<T>
Pool to obtain ChunkBuf<T>s