Struct Arena

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

Arena should be lock-free

Trait Implementations§

Source§

impl Allocator for Arena

Source§

type Path = Arc<PathBuf>

Available on crate feature memmap and non-target_family="wasm" only.
The path type of the allocator.
Source§

fn reserved_bytes(&self) -> usize

Returns the number of bytes that are reserved by the allocator.
Source§

fn reserved_slice(&self) -> &[u8]

Returns the reserved bytes of the allocator specified in the Options::with_reserved.
Source§

unsafe fn reserved_slice_mut(&self) -> &mut [u8]

Returns the mutable reserved bytes of the allocator specified in the Options::with_reserved. Read more
Source§

unsafe fn alloc<T>(&self) -> Result<RefMut<'_, T, Self>, Error>

Allocates a T in the allocator. Read more
Source§

fn alloc_aligned_bytes<T>( &self, size: u32, ) -> Result<BytesRefMut<'_, Self>, Error>

Allocates a byte slice that can hold a well-aligned T and extra size bytes. Read more
Source§

fn alloc_bytes(&self, size: u32) -> Result<BytesRefMut<'_, Self>, Error>

Allocates a slice of memory in the allocator. Read more
Source§

fn allocated(&self) -> usize

Returns the number of bytes allocated by the allocator. Read more
Source§

fn raw_mut_ptr(&self) -> *mut u8

Returns the start pointer of the main memory of the allocator.
Source§

fn raw_ptr(&self) -> *const u8

Returns the start pointer of the main memory of the allocator.
Source§

unsafe fn clear(&self) -> Result<(), Error>

Clear the allocator. Read more
Source§

unsafe fn dealloc(&self, offset: u32, size: u32) -> bool

Deallocates the memory at the given offset and size, the offset..offset + size will be made to a segment, returns true if the deallocation is successful. Read more
Source§

fn discard_freelist(&self) -> Result<u32, Error>

Discards all freelist nodes in the allocator. Read more
Source§

fn discarded(&self) -> u32

Returns the number of bytes discarded by the allocator. Read more
Source§

fn increase_discarded(&self, size: u32)

Forcelly increases the discarded bytes. Read more
Source§

fn magic_version(&self) -> u16

Returns the magic version of the allocator. This value can be used to check the compatibility for application using Allocator. Read more
Source§

fn minimum_segment_size(&self) -> u32

Returns the minimum segment size of the allocator. Read more
Source§

fn set_minimum_segment_size(&self, size: u32)

Sets the minimum segment size of the allocator. Read more
Source§

fn path(&self) -> Option<&Self::Path>

Available on crate feature memmap and non-target_family="wasm" only.
Returns the path of the mmap file, only returns Some when the ARENA is backed by a mmap file. Read more
Source§

unsafe fn offset(&self, ptr: *const u8) -> usize

Returns the offset to the start of the allocator. Read more
Source§

fn page_size(&self) -> usize

Returns the page size. Read more
Source§

fn read_only(&self) -> bool

Returns true if the arena is read-only. Read more
Source§

fn refs(&self) -> usize

Returns the number of references to the allocator. Read more
Source§

fn remaining(&self) -> usize

Returns the number of bytes remaining bytes can be allocated by the allocator. Read more
Source§

unsafe fn rewind(&self, pos: ArenaPosition)

Set back the allocator’s main memory cursor to the given position. Read more
Source§

fn version(&self) -> u16

Returns the version of the allocator. Read more
Source§

fn alloc_aligned_bytes_owned<T>( &self, size: u32, ) -> Result<BytesMut<Self>, Error>

Allocates an owned byte slice that can hold a well-aligned T and extra size bytes. Read more
Source§

fn alloc_bytes_owned(&self, size: u32) -> Result<BytesMut<Self>, Error>

Allocates an owned slice of memory in the allocator. Read more
Source§

unsafe fn alloc_owned<T>(&self) -> Result<Owned<T, Self>, Error>

Allocates a T in the allocator. Like alloc, but returns an Owned. Read more
Source§

fn allocated_memory(&self) -> &[u8]

Returns the whole main memory of the allocator as a byte slice. Read more
Source§

fn capacity(&self) -> usize

Returns the capacity of the allocator. Read more
Source§

fn data_offset(&self) -> usize

Returns the data offset of the allocator. The offset is the end of the reserved bytes of the allocator. Read more
Source§

fn data(&self) -> &[u8]

Returns the data section of the allocator as a byte slice, header is not included. Read more
Source§

fn flush(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Flushes the memory-mapped file to disk. Read more
Source§

fn flush_async(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Flushes the memory-mapped file to disk asynchronously. Read more
Source§

fn flush_range(&self, offset: usize, len: usize) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Flushes outstanding memory map modifications in the range to disk. Read more
Source§

fn flush_async_range(&self, offset: usize, len: usize) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Asynchronously flushes outstanding memory map modifications in the range to disk. Read more
Source§

fn flush_header(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Flushes outstanding memory map modifications in Allocator’s header to disk. Read more
Source§

fn flush_async_header(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Asynchronously flushes outstanding memory map modifications Allocator’s header to disk. Read more
Source§

fn flush_header_and_range(&self, offset: usize, len: usize) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Flushes outstanding memory map modifications in the range and Allocator’s header to disk. Read more
Source§

fn flush_async_header_and_range(&self, offset: usize, len: usize) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Asynchronously flushes outstanding memory map modifications in the range and Allocator’s header to disk. Read more
Source§

unsafe fn get_pointer(&self, offset: usize) -> *const u8

Returns a pointer to the memory at the given offset. Read more
Source§

unsafe fn get_pointer_mut(&self, offset: usize) -> *mut u8

Returns a pointer to the memory at the given offset. If the allocator is read-only, then this method will return a null pointer. Read more
Source§

unsafe fn get_aligned_pointer<T>(&self, offset: usize) -> *const T

Returns an aligned pointer to the memory at the given offset. Read more
Source§

unsafe fn get_aligned_pointer_mut<T>(&self, offset: usize) -> NonNull<T>

Returns an aligned pointer to the memory at the given offset. If the allocator is read-only, then this method will return a null pointer. Read more
Source§

unsafe fn get_bytes(&self, offset: usize, size: usize) -> &[u8]

Returns a bytes slice from the allocator. Read more
Source§

fn get_u8(&self, offset: usize) -> Result<u8, Error>

Returns a u8 from the allocator.
Source§

fn get_i8(&self, offset: usize) -> Result<i8, Error>

Returns a i8 from the allocator.
Source§

unsafe fn get_u8_unchecked(&self, offset: usize) -> u8

Returns a u8 from the allocator without bounds checking. Read more
Source§

unsafe fn get_i8_unchecked(&self, offset: usize) -> i8

Returns a i8 from the allocator without bounds checking. Read more
Source§

fn get_u16_be(&self, offset: usize) -> Result<u16, Error>

Returns a u16 from the allocator.
Source§

unsafe fn get_u16_be_unchecked(&self, offset: usize) -> u16

Returns a u16 from the allocator without bounds checking. Read more
Source§

fn get_u16_le(&self, offset: usize) -> Result<u16, Error>

Returns a u16 from the allocator.
Source§

unsafe fn get_u16_le_unchecked(&self, offset: usize) -> u16

Returns a u16 from the allocator without bounds checking. Read more
Source§

fn get_u32_be(&self, offset: usize) -> Result<u32, Error>

Returns a u32 from the allocator.
Source§

unsafe fn get_u32_be_unchecked(&self, offset: usize) -> u32

Returns a u32 from the allocator without bounds checking. Read more
Source§

fn get_u32_le(&self, offset: usize) -> Result<u32, Error>

Returns a u32 from the allocator.
Source§

unsafe fn get_u32_le_unchecked(&self, offset: usize) -> u32

Returns a u32 from the allocator without bounds checking. Read more
Source§

fn get_u64_be(&self, offset: usize) -> Result<u64, Error>

Returns a u64 from the allocator.
Source§

unsafe fn get_u64_be_unchecked(&self, offset: usize) -> u64

Returns a u64 from the allocator without bounds checking. Read more
Source§

fn get_u64_le(&self, offset: usize) -> Result<u64, Error>

Returns a u64 from the allocator.
Source§

unsafe fn get_u64_le_unchecked(&self, offset: usize) -> u64

Returns a u64 from the allocator without bounds checking. Read more
Source§

fn get_u128_be(&self, offset: usize) -> Result<u128, Error>

Returns a u128 from the allocator.
Source§

unsafe fn get_u128_be_unchecked(&self, offset: usize) -> u128

Returns a u128 from the allocator without bounds checking. Read more
Source§

fn get_u128_le(&self, offset: usize) -> Result<u128, Error>

Returns a u128 from the allocator.
Source§

unsafe fn get_u128_le_unchecked(&self, offset: usize) -> u128

Returns a u128 from the allocator without bounds checking. Read more
Source§

fn get_i16_be(&self, offset: usize) -> Result<i16, Error>

Returns a i16 from the allocator.
Source§

unsafe fn get_i16_be_unchecked(&self, offset: usize) -> i16

Returns a i16 from the allocator without bounds checking. Read more
Source§

fn get_i16_le(&self, offset: usize) -> Result<i16, Error>

Returns a i16 from the allocator.
Source§

unsafe fn get_i16_le_unchecked(&self, offset: usize) -> i16

Returns a i16 from the allocator without bounds checking. Read more
Source§

fn get_i32_be(&self, offset: usize) -> Result<i32, Error>

Returns a i32 from the allocator.
Source§

unsafe fn get_i32_be_unchecked(&self, offset: usize) -> i32

Returns a i32 from the allocator without bounds checking. Read more
Source§

fn get_i32_le(&self, offset: usize) -> Result<i32, Error>

Returns a i32 from the allocator.
Source§

unsafe fn get_i32_le_unchecked(&self, offset: usize) -> i32

Returns a i32 from the allocator without bounds checking. Read more
Source§

fn get_i64_be(&self, offset: usize) -> Result<i64, Error>

Returns a i64 from the allocator.
Source§

unsafe fn get_i64_be_unchecked(&self, offset: usize) -> i64

Returns a i64 from the allocator without bounds checking. Read more
Source§

fn get_i64_le(&self, offset: usize) -> Result<i64, Error>

Returns a i64 from the allocator.
Source§

unsafe fn get_i64_le_unchecked(&self, offset: usize) -> i64

Returns a i64 from the allocator without bounds checking. Read more
Source§

fn get_i128_be(&self, offset: usize) -> Result<i128, Error>

Returns a i128 from the allocator.
Source§

unsafe fn get_i128_be_unchecked(&self, offset: usize) -> i128

Returns a i128 from the allocator without bounds checking. Read more
Source§

fn get_i128_le(&self, offset: usize) -> Result<i128, Error>

Returns a i128 from the allocator.
Source§

unsafe fn get_i128_le_unchecked(&self, offset: usize) -> i128

Returns a i128 from the allocator without bounds checking. Read more
Source§

fn get_i16_varint(&self, offset: usize) -> Result<(usize, i16), Error>

Returns a i16 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_i32_varint(&self, offset: usize) -> Result<(usize, i32), Error>

Returns a i32 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_i64_varint(&self, offset: usize) -> Result<(usize, i64), Error>

Returns a i64 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_i128_varint(&self, offset: usize) -> Result<(usize, i128), Error>

Returns a i128 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_u16_varint(&self, offset: usize) -> Result<(usize, u16), Error>

Returns a u16 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_u32_varint(&self, offset: usize) -> Result<(usize, u32), Error>

Returns a u32 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_u64_varint(&self, offset: usize) -> Result<(usize, u64), Error>

Returns a u64 in LEB128 format from the allocator at the given offset. Read more
Source§

fn get_u128_varint(&self, offset: usize) -> Result<(usize, u128), Error>

Returns a u128 in LEB128 format from the allocator at the given offset. Read more
Source§

unsafe fn get_bytes_mut(&self, offset: usize, size: usize) -> &mut [u8]

Returns a mutable bytes slice from the allocator. If the allocator is read-only, then this method will return an empty slice. Read more
Source§

fn is_map(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.
Returns true if the allocator is created through memory map. Read more
Source§

fn is_ondisk(&self) -> bool

Returns true if the allocator is on disk. Read more
Source§

fn is_inmemory(&self) -> bool

Returns true if the allocator is in memory. Read more
Source§

fn is_map_anon(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.
Returns true if the allocator is on-disk and created through memory map. Read more
Source§

fn is_map_file(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.
Returns true if the allocator is on-disk and created through memory map. Read more
Source§

fn lock_exclusive(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Locks the underlying file for exclusive access, only works on mmap with a file backend. Read more
Source§

fn lock_shared(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Locks the underlying file for shared access, only works on mmap with a file backend. Read more
Source§

fn memory(&self) -> &[u8]

Returns the whole main memory of the allocator as a byte slice. Read more
Source§

fn checksum<S: BuildChecksumer>(&self, cks: &S) -> u64

Calculates the checksum of the allocated memory (excluding the reserved memory specified by users through Options::with_reserved) of the allocator.
Source§

fn unify(&self) -> bool

Returns true if the allocator is unify memory layout. Read more
Source§

unsafe fn mlock(&self, offset: usize, len: usize) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
mlock(ptr, len)—Lock memory into RAM. Read more
Source§

unsafe fn munlock(&self, offset: usize, len: usize) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
munlock(ptr, len)—Unlock memory. Read more
Source§

fn remove_on_drop(&self, remove_on_drop: bool)

Available on crate feature memmap and non-target_family="wasm" only.
Sets remove on drop, only works on mmap with a file backend. Read more
Source§

fn try_lock_exclusive(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Try to lock the underlying file for exclusive access, only works on mmap with a file backend. Read more
Source§

fn try_lock_shared(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Try to lock the underlying file for shared access, only works on mmap with a file backend. Read more
Source§

fn unlock(&self) -> Result<()>

Available on crate feature memmap and non-target_family="wasm" only.
Unlocks the underlying file, only works on mmap with a file backend. Read more
Source§

impl Clone for Arena

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Arena

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Arena

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Arena

Source§

impl Sync for Arena

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<K, Q> Comparable<Q> for K
where K: Borrow<Q> + ?Sized, Q: Ord + ?Sized,

Source§

fn compare(&self, key: &Q) -> Ordering

Compare self to key and return their ordering.
Source§

impl<K, Q> Equivalent<Q> for K
where K: Borrow<Q> + ?Sized, Q: Eq + ?Sized,

Source§

fn equivalent(&self, key: &Q) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more