Skip to main content

BufferPool

Struct BufferPool 

Source
pub(crate) struct BufferPool {
    pub(crate) bufs: Mutex<Vec<Vec<u8>>>,
    pub(crate) buf_size: usize,
}
Expand description

Recycles outgoing frame buffers from dropped AudioFrames back to the capture thread, so the steady-state emit path allocates nothing.

INVARIANT: every buffer is born as vec![0u8; buf_size], so bytes [0, buf_size) stay initialized for the allocation’s whole lifetime — truncate only shortens len, never de-initializes memory. That is what makes restore’s set_len back to buf_size sound.

Fields§

§bufs: Mutex<Vec<Vec<u8>>>§buf_size: usize

Implementations§

Source§

impl BufferPool

Source

pub(crate) const MAX_POOLED: usize = 16

Cap on pooled buffers. Outstanding frames rarely exceed the delivery-ring capacity plus a few Python-held references; anything past this goes back to the allocator rather than growing the pool unboundedly.

Source

pub(crate) fn new(buf_size: usize) -> Self

Create an empty pool that hands out (and accepts) buf_size-byte buffers.

Source

pub(crate) fn restore(&self, v: Vec<u8>) -> Vec<u8>

Restore a recycled buffer to full buf_size length via set_len.

Sound per the pool invariant: the bytes were written at allocation and truncation does not de-initialize them, so extending len back to buf_size never exposes uninitialized memory.

Source

pub(crate) fn put(&self, v: Vec<u8>)

Return a buffer to the pool, unless it is undersized or the pool is already at MAX_POOLED (in which case it is dropped to the allocator).

Source

pub(crate) fn drain_into(&self, into: &mut Vec<Vec<u8>>)

Move every pooled buffer into into under a single lock — the batched refill for the sole-consumer PoolTaker, whose empty local stash is into.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,