pub struct MorselArena { /* private fields */ }Expand description
Bump allocator for one morsel’s working memory.
Implementations§
Source§impl MorselArena
impl MorselArena
pub fn new() -> Self
Sourcepub fn alloc(&mut self, bytes: usize, align: usize) -> RawBuf
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).
Sourcepub fn alloc_of<T: Pod>(&mut self, count: usize) -> RawBuf
pub fn alloc_of<T: Pod>(&mut self, count: usize) -> RawBuf
Allocate a typed buffer for count values.
Sourcepub fn reset(&mut self)
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.
Sourcepub fn pooled() -> PooledArena
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.