#[doc(hidden)]pub struct ArenaState<M> {
pub map: MaybeUninit<M>,
pub backing: SEXP,
pub capacity: usize,
pub len: usize,
pub free_list: Vec<usize>,
pub next_slot: usize,
}Expand description
Core arena state without interior mutability.
This is used internally by both Arena (with RefCell) and
thread-local arenas (with UnsafeCell).
Fields§
§map: MaybeUninit<M>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<M: MapStorage> ArenaState<M>
impl<M: MapStorage> ArenaState<M>
Sourcepub const INITIAL_CAPACITY: usize = 16
pub 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 Arena::with_capacity or 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).
Sourcepub unsafe fn protect(&mut self, x: SEXP) -> SEXP
pub 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.
Sourcepub unsafe fn unprotect(&mut self, x: SEXP)
pub 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.
Sourcepub unsafe fn try_unprotect(&mut self, x: SEXP) -> bool
pub 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.
Sourcepub fn is_protected(&self, x: SEXP) -> bool
pub fn is_protected(&self, x: SEXP) -> bool
Returns true if this arena currently protects x.
Sourcepub fn ref_count(&self, x: SEXP) -> usize
pub 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)
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.