Expand description
A garbage-collected smart pointer library for Rust.
rudo-gc provides a Gc<T> smart pointer with automatic memory reclamation
and cycle detection. It uses a BiBOP (Big Bag of Pages) memory layout for
efficient O(1) allocation and a Mark-Sweep garbage collection algorithm.
§Features
- Automatic cycle detection: Unlike
Rc<T>,Gc<T>can collect cyclic references BiBOPmemory layout: O(1) allocation with size-class based segments- Non-moving GC: Address stability for Rust’s
&Treferences - Ergonomic API: Similar to
Rc<T>with#[derive(Trace)]for custom types
§Quick Start
ⓘ
use rudo_gc::{Gc, Trace};
// Simple allocation
let x = Gc::new(42);
println!("Value: {}", *x);
// Custom types with derive
#[derive(Trace)]
struct Node {
value: i32,
next: Option<Gc<Node>>,
}
let node = Gc::new(Node { value: 1, next: None });§Handling Cycles
ⓘ
use rudo_gc::{Gc, Trace, collect};
use std::cell::RefCell;
#[derive(Trace)]
struct Node {
next: RefCell<Option<Gc<Node>>>,
}
let a = Gc::new(Node { next: RefCell::new(None) });
let b = Gc::new(Node { next: RefCell::new(None) });
// Create cycle: a -> b -> a
*a.next.borrow_mut() = Some(Gc::clone(&b));
*b.next.borrow_mut() = Some(Gc::clone(&a));
drop(a);
drop(b);
collect(); // Cycle is detected and freedRe-exports§
pub use cell::GcCell;pub use cell::GcCapture;pub use cell::GcThreadSafeCell;pub use cell::GcThreadSafeRefMut;pub use gc::incremental::is_incremental_marking_active;pub use gc::incremental::is_write_barrier_active;pub use gc::incremental::mark_new_object_black;pub use gc::incremental::IncrementalConfig;pub use gc::incremental::IncrementalMarkState;pub use gc::incremental::MarkPhase;pub use gc::incremental::MarkSliceResult;pub use gc::incremental::MarkStats;pub use sync::GcMutex;pub use sync::GcRwLock;pub use gc::collect;pub use gc::collect_full;pub use gc::default_collect_condition;pub use gc::safepoint;pub use gc::set_collect_condition;pub use gc::set_gc_enabled;pub use gc::CollectInfo;pub use gc::PerThreadMarkQueue;pub use gc::StealQueue;pub use handles::AsyncHandle;pub use handles::AsyncHandleGuard;pub use handles::AsyncHandleScope;pub use handles::EscapeableHandleScope;pub use handles::Handle;pub use handles::HandleScope;pub use handles::MaybeHandle;pub use handles::SealedHandleScope;pub use metrics::FallbackReason;
Modules§
- cell
- Interior mutability with write barriers for Generational GC.
- gc
- Garbage collection coordination and parallel marking.
- handles
HandleScopev2 implementation for compile-time safe GC handles.- heap
BiBOPmemory management internals.- sync
- Concurrent GC primitives for thread-safe garbage-collected objects.
Macros§
- impl_
gc_ capture - Macro to implement
GcCapturefor types that don’t containGc<T>pointers.
Structs§
- Ephemeron
- An ephemeron is a key-value pair where the value is only reachable if the key is reachable.
- Gc
- A garbage-collected pointer to a value of type
T. - GcBox
- The actual heap allocation wrapping the user’s value.
- GcHistory
- Fixed-size ring buffer of recent
GcMetricssnapshots. - GcMetrics
- Statistics from the most recent garbage collection.
- Global
Metrics - Process-level cumulative GC statistics.
- Trace
Closure - A wrapper for a closure that captures and traces dependencies.
- Weak
- A weak reference to a garbage-collected value.
Enums§
- Collection
Type - Type of GC collection.
Traits§
- Trace
- A type that can be traced by the garbage collector.
- Visitor
- A visitor that traverses the object graph during garbage collection.
Functions§
- current_
heap_ size - Get the current heap size for this thread.
- current_
old_ size - Get the current old generation size for this thread.
- current_
young_ size - Get the current young generation size for this thread.
- gc_
history - Get the GC history ring buffer.
- get_
incremental_ config - Get the current incremental marking configuration.
- global_
metrics - Get the global cumulative GC metrics.
- is_
incremental_ gc_ enabled - Check if incremental GC is enabled.
- last_
gc_ metrics - Get metrics from the last garbage collection.
- scan_
heap_ ⚠region_ conservatively - Scan a memory region conservatively for potential Gc pointers.
- set_
incremental_ config - Configure incremental marking settings.
- yield_
now - Yield to the garbage collector for cooperative scheduling.
Derive Macros§
- Trace
- Derive macro for the
Tracetrait.