Crate rtgc

Crate rtgc 

Source
Expand description

A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.

The performance characteristics of the ArcGc, OwnedGc, and OwnedGcUnsized smart pointers are equivalant to Arc when reading (but constructing them is a bit more expensive).

§Example

let value_1 = ArcGc::new(String::from("foo"));
// Same as `ArcGc` but for `!Sync` data.
let value_2 = OwnedGc::new(String::from("bar"));

// A simulated "realtime thread"
let rt_thread = std::thread::spawn(move || {
    std::thread::sleep(Duration::from_millis(15));

    // Dropping the values on the realtime thread is realtime-safe
    // because the contents are automatically collected and
    // deallocated on a separate non-realtime thread.
    let _ = value_1;
    let _ = value_2;
});

// A simulated update loop on the main thread
for _ in 0..4 {
    // Call `GlobalRtGc::collect()` periodically to deallocate
    // any resources that were dropped on the realtime thread.
    GlobalRtGc::collect();

    std::thread::sleep(Duration::from_millis(15));
}

You can also use a non-static collector with LocalRtGc (enabled in the local_collector feature).

Structs§

ArcGc
A realtime-safe wrapper around Arc that when dropped, automatically has its contents collected and later deallocated on another non-realtime thread.
GlobalRtGc
A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
LocalRtGc
A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
LocalRtGcHandle
A handle to a LocalRtGc garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
OwnedGc
A realtime-safe !Sync resource that when dropped, automatically has its contents collected and later deallocated on another non-realtime thread.
OwnedGcUnsized
A realtime-safe !Sync resource that when dropped, automatically has its contents collected and later deallocated on another non-realtime thread.

Traits§

Collector
A trait which describes a garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
StrongCount
A trait for type-erasing Arc<T> types.