Expand description
Reference-counted GC protection using a BTreeMap + VECSXP backing.
This module provides an alternative to gc_protect that uses
reference counting instead of R’s LIFO protect stack. This allows releasing
protections in any order and avoids the --max-ppsize limit.
§Architecture
┌─────────────────────────────────────────────────────────────────────┐
│ RefCountedArena / ThreadLocalArena │
│ ┌─────────────────────────┐ ┌───────────────────────────────────┐│
│ │ BTreeMap<usize, Entry> │ │ VECSXP (R_PreserveObject'd) ││
│ │ ────────────────────── │ │ ───────────────────────────── ││
│ │ sexp_a → {count:2, i:0}│◄──┤ [0]: sexp_a ││
│ │ sexp_b → {count:1, i:1}│◄──┤ [1]: sexp_b ││
│ │ sexp_c → {count:1, i:2}│◄──┤ [2]: sexp_c ││
│ └─────────────────────────┘ │ [3]: <free> ││
│ └───────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────┘§Available Types
| Type | Storage | Use Case |
|---|---|---|
RefCountedArena | RefCell | General purpose, ordered, ppsize-scale workloads |
ThreadLocalArena | thread_local | Lowest overhead — no RefCell borrow checking |
Only these two flavors are instantiated anywhere in the tree today. This
module previously also shipped HashMap- and ahash-backed variants
(HashMapArena, ThreadLocalHashArena, FastHashMapArena,
ThreadLocalFastHashArena) behind a generic MapStorage abstraction; they
were removed for having zero production or test consumers (see
https://github.com/a2-ai/miniextendr/issues/ISSUE_NUMBER_PLACEHOLDER).
Re-add a flavor (and the generic MapStorage plumbing needed to support
more than one map type again) when a real consumer appears.
Structs§
- Arena
Guard - An RAII guard that unprotects a SEXP when dropped.
- Arena
State 🔒 - Core arena state without interior mutability.
- Entry 🔒
- Entry in the reference count map.
- RefCounted
Arena - A reference-counted arena for GC protection, backed by a
BTreeMap. - Thread
Local Arena - Thread-local,
BTreeMap-backed reference-counted GC protection arena. - Thread
Local 🔒State - State wrapper for the thread-local arena.
Constants§
Type Aliases§
- NoSend
Sync 🔒 - Enforces
!Send + !Sync(R API is not thread-safe).