struct ArenaState {
map: MaybeUninit<BTreeMap<usize, Entry>>,
backing: SEXP,
capacity: usize,
len: usize,
free_list: Vec<usize>,
next_slot: usize,
}Expand description
Core arena state without interior mutability.
This is used internally by both RefCountedArena (with RefCell) and
ThreadLocalArena (with UnsafeCell).
Fields§
§map: MaybeUninit<BTreeMap<usize, Entry>>Map from SEXP pointer to entry
backing: SEXPBacking VECSXP (preserved via R_PreserveObject)
capacity: usizeCurrent capacity
len: usizeNumber of active entries
free_list: Vec<usize>Free list for slot reuse
next_slot: usizeMonotonic write cursor: next index to hand out on the fresh-slot path.
Distinct from len (live count) — after release cycles len can be
lower than the highest index ever handed out, so using len as the
cursor can return an index that is already on the free-list.
Implementations§
Source§impl ArenaState
impl ArenaState
Sourceconst INITIAL_CAPACITY: usize = 16
const INITIAL_CAPACITY: usize = 16
Initial capacity for the backing VECSXP.
This is suitable for light usage (a handful of protected values).
For ppsize-scale workloads (hundreds or thousands of protected values),
use RefCountedArena::with_capacity or
ThreadLocalArena::init_with_capacity to avoid repeated backing
VECSXP growth and map rehashing.
Sourceconst MAX_CAPACITY: usize
const MAX_CAPACITY: usize
Maximum capacity: the backing VECSXP is indexed by R_xlen_t (isize),
so the capacity must fit in a non-negative R_xlen_t.
Sourcefn capacity_as_r_xlen(cap: usize) -> R_xlen_t
fn capacity_as_r_xlen(cap: usize) -> R_xlen_t
Convert a usize capacity to R_xlen_t, panicking on overflow.
Sourceunsafe fn init_backing(&mut self, capacity: usize)
unsafe fn init_backing(&mut self, capacity: usize)
Initialize just the backing (map already initialized).
Sourcefn decrement_and_maybe_remove(&mut self, key: &usize) -> Option<(bool, usize)>
fn decrement_and_maybe_remove(&mut self, key: &usize) -> Option<(bool, usize)>
Decrement the count for a key and remove if zero.
Returns Some((true, index)) if the entry was found and removed,
Some((false, index)) if the entry was found but count > 0 after
decrement, None if the entry was not found.
Sourceunsafe fn protect(&mut self, x: SEXP) -> SEXP
unsafe fn protect(&mut self, x: SEXP) -> SEXP
Protect a SEXP from garbage collection.
§Safety
Must be called from the R main thread. The SEXP must be valid.
Sourceunsafe fn unprotect(&mut self, x: SEXP)
unsafe fn unprotect(&mut self, x: SEXP)
Unprotect a SEXP, allowing garbage collection when refcount reaches zero.
§Safety
Must be called from the R main thread. The SEXP must have been previously protected by this arena.
Sourceunsafe fn try_unprotect(&mut self, x: SEXP) -> bool
unsafe fn try_unprotect(&mut self, x: SEXP) -> bool
Try to unprotect a SEXP. Returns false if not protected by this arena.
§Safety
Must be called from the R main thread.
Sourcefn is_protected(&self, x: SEXP) -> bool
fn is_protected(&self, x: SEXP) -> bool
Returns true if this arena currently protects x.
Sourcefn ref_count(&self, x: SEXP) -> usize
fn ref_count(&self, x: SEXP) -> usize
Returns the current reference count for x in this arena.
Returns 0 if x is not protected or is SEXP::nil().
fn allocate_slot(&mut self) -> usize
unsafe fn grow(&mut self)
unsafe fn release_backing(&mut self)
Auto Trait Implementations§
impl Freeze for ArenaState
impl RefUnwindSafe for ArenaState
impl Send for ArenaState
impl Sync for ArenaState
impl Unpin for ArenaState
impl UnsafeUnpin for ArenaState
impl UnwindSafe for ArenaState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 80 bytes