Skip to main content

MorselArena

Struct MorselArena 

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

Bump allocator for one morsel’s working memory.

Implementations§

Source§

impl MorselArena

Source

pub fn new() -> Self

Source

pub fn alloc(&mut self, bytes: usize, align: usize) -> RawBuf

Bump-allocate bytes with the given alignment (a power of two, at most 64: blocks themselves are 64-byte aligned so any larger request could not be honored from a bump offset).

Source

pub fn alloc_of<T: Pod>(&mut self, count: usize) -> RawBuf

Allocate a typed buffer for count values.

Source

pub fn reset(&mut self)

O(1) reset: keep the blocks, rewind the offsets. Called once per morsel. Buffers handed out before the reset are dead; debug builds catch any survivor on its next access.

Source

pub fn capacity(&self) -> usize

Bytes currently held, for budget accounting.

Source

pub fn pooled() -> PooledArena

An arena off this thread’s pool, or a new one when the pool is empty, handed back to the pool when it is dropped.

An arena is born per run and dies with it, so a warm query that allocates nothing per morsel still pays three trips to the heap before its first row: the block list, the generation counter and the first block, which at eight kilobytes is most of what a warm point read asks the allocator for. None of that is about the run. A thread runs one worker at a time and the pool threads outlive any one query, so the arena the last query left is the arena this one wants.

Reuse is safe for the same reason a reset is: taking one resets it, which moves the generation, so a buffer that outlived the query it was cut from fails its tag in debug rather than reading the next query’s bytes.

Trait Implementations§

Source§

impl Default for MorselArena

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<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.