Skip to main content

BufPool

Struct BufPool 

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

A pool of byte buffers in size classes. See the module docs.

Implementations§

Source§

impl BufPool

Source

pub fn new(classes: [usize; 3], max_cached: usize) -> BufPool

A pool with the given class sizes (ascending) and at most max_cached buffers kept per class (the larger classes keep a quarter and a sixteenth of that).

Source

pub fn classes(&self) -> [usize; 3]

The class sizes.

Source

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

An empty buffer with capacity of at least min bytes: the smallest class that fits, or exactly min when it is larger than every class.

Source

pub fn put(&mut self, buf: Vec<u8>)

Takes a buffer back. It is cleared and kept if its capacity is a class size and that class is not full; otherwise it is freed. Out of line: it is called from many places in the loop, and a call costs nothing next to the free or push it ends in.

Source

pub fn trim(&mut self, keep: usize)

Frees cached buffers until at most keep remain in each class (for trimming after a burst).

Source

pub fn stats(&self) -> PoolStats

Counters.

Trait Implementations§

Source§

impl Debug for BufPool

Source§

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

Formats the value using the given formatter. 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<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 = !

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.