| Crates.io | pgc |
| lib.rs | pgc |
| version | 0.3.0 |
| created_at | 2019-09-25 17:06:09.352107+00 |
| updated_at | 2019-09-28 04:27:16.193635+00 |
| description | Garbage collector |
| homepage | |
| repository | https://github.com/playXE/pgc |
| max_upload_size | |
| id | 167589 |
| size | 67,393 |
Precise tracing garbage collector built in Rust featuring parallel marking and mark&sweep algorithm.
To include in your project, add the following to your Cargo.toml:
[dependencies]
pgc = "*"
This can be used pretty much like Rc, with the exception of interior mutability.
Types placed inside a Gc and Rooted must implement GcObject and Send.
use pgc::*;
struct Foo {
x: Gc<i32>,
y: i32
}
unsafe impl GcObject for Foo {
fn references(&self) -> Vec<Gc<dyn GcObject>> {
let mut v: Vec<Gc<dyn GcObject>> = vec![];
v.push(self.x);
v
}
}
To use Gc simply call Gc::new:
let foo = Gc::new(Foo {...});
GC does not scan program stack for root objects so you should add roots explicitly:
let foo = Gc::new(Foo {...});
add_root(foo);
... // do something with `foo`
remove_root(foo);
// Or use `Rooted` struct that will unroot object automatically:
let foo = Rooted:new(Foo {...});
gc_mark in your code.