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
Chunk
s, 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 Vec
s 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
ChunkBuf<T>
s