Expand description
R-backed global allocator for Rust.
Allocations are backed by R RAWSXP objects and protected from GC via
R_PreserveObject/R_ReleaseObject (R’s precious list).
§Protection Strategy
This allocator uses R_PreserveObject directly because:
- Allocations may need to survive across multiple
.Callinvocations - The SEXP (RAWSXP) is its own handle — zero Rust-side bookkeeping
- LIFO release pattern (recently allocated = first freed) means O(1) release in practice (R’s precious list scans from head)
See the crate-level documentation for an overview of miniextendr’s protection mechanisms.
§Layout
Layout inside the RAWSXP (bytes): [optional leading pad][Header][user bytes…]
We always return a pointer aligned to at least:
max(requested_align, align_of::<Header>())
so the Header placed immediately before the user pointer is always aligned.
§⚠️ Warning: longjmp Risk
R’s Rf_allocVector can longjmp on allocation failure instead of returning
NULL. If this happens, Rust destructors will NOT run, potentially causing:
- Resource leaks (files, locks, etc.)
- Corrupted state if allocation happens mid-operation
This allocator is best suited for:
- Short-lived operations within a single R API call
- Contexts where
R_UnwindProtectis active (e.g., insiderun_on_worker)
For long-lived allocations or critical cleanup requirements, consider using Rust’s standard allocator instead.
Structs§
- Header 🔒
- Metadata stored immediately before the returned user pointer.
- RAllocator
- R-backed global allocator.
Constants§
Functions§
- alloc_
main_ 🔒 ⚠thread - Allocate memory on the R main thread.
- dealloc_
main_ 🔒 ⚠thread - Deallocate memory on the R main thread.
- realloc_
main_ 🔒 ⚠thread - Reallocate memory on the R main thread.
- sendable_
data_ 🔒ptr_ get - sendable_
data_ 🔒ptr_ is_ null - sendable_
data_ 🔒ptr_ new - sendable_
data_ 🔒ptr_ null - with_
r_ 🔒thread_ or_ inline - Routes a closure to the R main thread if not already there.
Type Aliases§
- Sendable
Data 🔒Ptr - Wrapper to make
*mut u8pointersSendfor cross-thread routing.