Skip to main content

FramePool

Struct FramePool 

Source
pub struct FramePool { /* private fields */ }
Expand description

Buffers handed back for reuse, so steady-state playback allocates nothing.

Decoding 24 frames a second means 24 allocations a second of several megabytes each; at 4K that is enough to keep an allocator busy and enough to fragment one. Frames come back here when the renderer is done with them.

Implementations§

Source§

impl FramePool

Source

pub fn new(capacity: usize) -> Self

A pool holding at most capacity buffers.

Bounded on purpose: an unbounded pool is a memory leak that happens to be spelled differently.

Source

pub fn take(&mut self, size: usize) -> Vec<u8> ⓘ

A buffer of at least size bytes, cleared to that length.

Source

pub fn give(&mut self, buffer: Vec<u8>)

Offers a buffer back. Dropped if the pool is full.

Source

pub fn reclaim(&mut self, frame: Frame)

Takes a frame’s buffer back if nothing else still holds it.

A frame the renderer is still reading is left alone — which is the point of the Arc: reuse is an optimisation, never a race.

Source

pub fn statistics(&self) -> (u64, u64)

How many take calls were answered without allocating, and how many were not. Steady-state playback should stop adding to the second.

Trait Implementations§

Source§

impl Debug for FramePool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FramePool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.