pub struct ArenaPool { /* private fields */ }Expand description
Pool of reusable byte buffers for arena-backed frame allocations.
Construct one per decoder via ArenaPool::new. Lease an
Arena per frame via ArenaPool::lease; drop the arena (or
drop the last clone of a Frame holding it) to return its
buffer to the pool.
Backpressure: when all max_arenas slots are checked out the
next ArenaPool::lease returns
Error::ResourceExhausted. A decoder that hits this should
surface the error to its caller rather than busy-loop — the
upstream pipeline is supposed to drop frames it no longer needs,
which returns a buffer to the pool.
ArenaPool is Send + Sync (the inner Mutex<Vec<…>> makes it
safe to share across threads even though Arena / Frame
themselves are !Send due to their Rc/Cell contents). This
asymmetry is intentional: a parallel-decoder thread can share a
single pool while each thread owns its own arenas — see also the
sibling sync::ArenaPool whose leases are themselves Send + Sync.
Implementations§
Source§impl ArenaPool
impl ArenaPool
Sourcepub fn new(max_arenas: usize, cap_per_arena: usize) -> Arc<Self> ⓘ
pub fn new(max_arenas: usize, cap_per_arena: usize) -> Arc<Self> ⓘ
Construct a new pool with max_arenas buffer slots, each of
cap_per_arena bytes. Buffers are allocated lazily on first
lease — a freshly constructed pool holds no memory.
Per-arena allocation count is capped at max_alloc_count (use
ArenaPool::new which defaults to a generous 1M, or
ArenaPool::with_alloc_count_cap to tighten further).
Sourcepub fn with_alloc_count_cap(
max_arenas: usize,
cap_per_arena: usize,
max_alloc_count_per_arena: u32,
) -> Arc<Self> ⓘ
pub fn with_alloc_count_cap( max_arenas: usize, cap_per_arena: usize, max_alloc_count_per_arena: u32, ) -> Arc<Self> ⓘ
Like ArenaPool::new but lets the caller set the per-arena
allocation-count cap. Useful when the caller is plumbing
crate::DecoderLimits through.
Sourcepub fn cap_per_arena(&self) -> usize
pub fn cap_per_arena(&self) -> usize
Capacity of each arena buffer this pool hands out, in bytes.
Sourcepub fn max_arenas(&self) -> usize
pub fn max_arenas(&self) -> usize
Maximum number of arenas that may be checked out at once.