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).