pub struct RefCountedArena {
state: RefCell<ArenaState>,
_nosend: PhantomData<Rc<()>>,
}Expand description
A reference-counted arena for GC protection, backed by a BTreeMap.
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)
Fields§
§state: RefCell<ArenaState>§_nosend: PhantomData<Rc<()>>Implementations§
Source§impl RefCountedArena
impl RefCountedArena
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<'_>
pub unsafe fn guard(&self, x: SEXP) -> ArenaGuard<'_>
Trait Implementations§
Source§impl Default for RefCountedArena
impl Default for RefCountedArena
Source§impl Drop for RefCountedArena
impl Drop for RefCountedArena
Auto Trait Implementations§
impl !Freeze for RefCountedArena
impl !RefUnwindSafe for RefCountedArena
impl !Send for RefCountedArena
impl !Sync for RefCountedArena
impl Unpin for RefCountedArena
impl UnsafeUnpin for RefCountedArena
impl UnwindSafe for RefCountedArena
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: 88 bytes