pub struct Arena<M: MapStorage> {
state: RefCell<ArenaState<M>>,
_nosend: PhantomData<Rc<()>>,
}Expand description
A reference-counted arena for GC protection, generic over map type.
This provides an alternative to R’s PROTECT stack that:
- Uses reference counting for each SEXP
- Allows releasing protections in any order
- Has no stack size limit (uses heap allocation)
§Type Aliases
RefCountedArena=Arena<BTreeMap<...>>(ordered, good for ref counting)HashMapArena=Arena<HashMap<...>>(faster for large collections)
Fields§
§state: RefCell<ArenaState<M>>§_nosend: PhantomData<Rc<()>>Implementations§
Source§impl<M: MapStorage> Arena<M>
impl<M: MapStorage> Arena<M>
Sourcepub unsafe fn new() -> Self
pub unsafe fn new() -> Self
Create a new arena with default capacity (16 slots).
For workloads protecting many distinct SEXPs (e.g., ppsize-scale loops),
prefer with_capacity to avoid backing VECSXP
growth and map rehashing during operation.
§Safety
Must be called from the R main thread.
Sourcepub unsafe fn with_capacity(capacity: usize) -> Self
pub unsafe fn with_capacity(capacity: usize) -> Self
Create a new arena with specific initial capacity.
Pre-sizing the arena avoids growth of the backing VECSXP and rehashing of the internal map. Use this when the expected number of distinct protected values is known or can be estimated.
§Safety
Must be called from the R main thread.
Sourcepub unsafe fn try_unprotect(&self, x: SEXP) -> bool
pub unsafe fn try_unprotect(&self, x: SEXP) -> bool
Try to unprotect a SEXP, returning true if it was protected.
§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
Check if a SEXP is currently protected by this arena.
Sourcepub fn ref_count(&self, x: SEXP) -> usize
pub fn ref_count(&self, x: SEXP) -> usize
Get the reference count for a SEXP (0 if not protected).
Sourcepub unsafe fn guard(&self, x: SEXP) -> ArenaGuard<'_, M>
pub unsafe fn guard(&self, x: SEXP) -> ArenaGuard<'_, M>
Trait Implementations§
Source§impl<M: MapStorage> Default for Arena<M>
impl<M: MapStorage> Default for Arena<M>
Source§impl<M: MapStorage> Drop for Arena<M>
impl<M: MapStorage> Drop for Arena<M>
Auto Trait Implementations§
impl<M> !Freeze for Arena<M>
impl<M> !RefUnwindSafe for Arena<M>
impl<M> !Send for Arena<M>
impl<M> !Sync for Arena<M>
impl<M> Unpin for Arena<M>where
M: Unpin,
impl<M> UnsafeUnpin for Arena<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for Arena<M>where
M: UnwindSafe,
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> SizeEq<MaybeUninit<T>> for T
impl<T> SizeEq<MaybeUninit<T>> for T
type CastFrom = CastSizedExact
Source§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 moreimpl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> InvariantsEq<ManuallyDrop<T>> for Twhere
T: ?Sized,
impl<T> InvariantsEq<T> for Twhere
T: ?Sized,
impl<T> InvariantsEq<Unalign<T>> for T
impl<T> InvariantsEq<Wrapping<T>> for T
impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T
impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T
impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
C: CastExact<Src, Dst>,
Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized,
Src: ?Sized,
impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized,
C: CastExact<Src, Dst>,
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.