Skip to main content

Arena

Struct Arena 

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

A bump allocator for row data.

Memory is allocated in contiguous chunks. Each alloc call bumps a pointer forward. There is no per-allocation deallocation — the entire arena is freed at once via reset() or Drop.

§Example

use bsql_arena::Arena;

let mut arena = Arena::new();
let offset = arena.alloc_copy(b"hello");
assert_eq!(arena.get(offset, 5), b"hello");
arena.reset();

Implementations§

Source§

impl Arena

Source

pub fn new() -> Arena

Create a new arena with an 8KB initial chunk.

Source

pub fn empty() -> Arena

Create an empty arena with zero allocation.

No memory is allocated until alloc or alloc_copy is called. Used by query paths that store data in QueryResult.data_buf instead.

Source

pub fn alloc(&mut self, len: usize) -> &mut [u8]

Allocate len bytes, returning a mutable slice into the arena.

The returned slice is zeroed. For copying data in, prefer alloc_copy.

Source

pub fn alloc_copy(&mut self, data: &[u8]) -> usize

Copy data into the arena and return the global offset.

The offset can be used with get() to retrieve the data later.

Source

pub fn get(&self, global_offset: usize, len: usize) -> &[u8]

Retrieve a slice from the arena by global offset and length.

§Panics

Panics if the offset + length exceeds the arena’s allocated range.

Source

pub fn get_str(&self, global_offset: usize, len: usize) -> Option<&str>

Retrieve a str slice from the arena. Returns None if not valid UTF-8.

Uses SIMD-accelerated UTF-8 validation via simdutf8.

Source

pub fn reset(&mut self)

Reset the arena for reuse. Keeps allocated memory but resets the bump pointer.

Chunks larger than 64KB are discarded to prevent long-term bloat.

Source

pub fn allocated(&self) -> usize

Total bytes allocated in this arena (across all chunks).

Source

pub fn capacity(&self) -> usize

Total capacity of all chunks (for diagnostics).

Source

pub fn global_offset(&self) -> usize

Compute the global offset for the current position.

Trait Implementations§

Source§

impl Default for Arena

Source§

fn default() -> Arena

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

Auto Trait Implementations§

§

impl Freeze for Arena

§

impl RefUnwindSafe for Arena

§

impl Send for Arena

§

impl Sync for Arena

§

impl Unpin for Arena

§

impl UnsafeUnpin for Arena

§

impl UnwindSafe for Arena

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> Same for T

Source§

type Output = T

Should always be Self
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.