1
2
Fork
You've already forked rtgc
0
A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread
Rust 100%
2025年11月15日 09:39:36 -06:00
src edit docs for triple buffer types 2025年11月15日 09:39:36 -06:00
.gitignore Initial commit 2025年10月27日 00:31:18 +01:00
Cargo.toml edit docs for triple buffer types 2025年11月15日 09:39:36 -06:00
LICENSE Initial commit 2025年10月27日 00:31:18 +01:00
README.md mention new triple buffer types in readme 2025年11月14日 21:15:57 -06:00

Real-Time Garbage Collector

Documentation Crates.io License

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

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

This crate also contains optional triple buffer types for syncing data (enable with the triple_buffer feature).

Optional support for no_std is provided through the use of bevy_platform.

This crate is similar to basedrop, except that it uses a simpler algorithm which makes use of standard library types as much as possible to greatly reduce the amount of internal unsafe code. (It is also not susceptible to memory leaks.) The drawback is that the collection pass is a bit more expensive than basedrop's implementation.

Example

usestd::time::Duration;usertgc::*;letvalue_1=ArcGc::new(String::from("foo"));// Same as `ArcGc` but for `!Sync` data.
letvalue_2=OwnedGc::new(String::from("bar"));// A simulated "realtime thread"
letrt_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_in0..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).