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
impl Arena
Sourcepub fn empty() -> Arena
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.
Sourcepub fn alloc(&mut self, len: usize) -> &mut [u8] ⓘ
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.
Sourcepub fn alloc_copy(&mut self, data: &[u8]) -> usize
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.
Sourcepub fn get(&self, global_offset: usize, len: usize) -> &[u8] ⓘ
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.
Sourcepub fn get_str(&self, global_offset: usize, len: usize) -> Option<&str>
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.
Sourcepub fn reset(&mut self)
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.
Sourcepub fn global_offset(&self) -> usize
pub fn global_offset(&self) -> usize
Compute the global offset for the current position.