Crates.io | cgc-single-threaded |
lib.rs | cgc-single-threaded |
version | 0.1.1 |
source | src |
created_at | 2020-04-29 08:40:40.241318 |
updated_at | 2020-05-01 11:07:02.947675 |
description | Compacting garbage collector |
homepage | |
repository | https://github.com/playXE/cgc |
max_upload_size | |
id | 235257 |
size | 67,701 |
cgc is generational copying garbage collector.
This branch implements signle-threaded version that does not have anything to deal with concurrency and synchronization.
cgc uses semispace garbage collection to keep GC simple and generations to improve GC latency.
cgc supports logging. To alloc printing trace add feature trace-gc
to features and to pring GC timings
add trace-gc-timings
feature.
Advantages of broom
:
Less dependencies (depends only on one crate hashbrown
).
Very small & simple implementation.
Disadvantages of broom
:
Advantages of gc
:
No dependencies
Easy to make GC object,just use #[derive(Trace)]
.
Disadvantages of gc
:
gc
crate has the same disadvantages as broom
crate, it uses mark'n sweep and does not have any memory defragmentation.
cgc is simple to use all you have to do is implement Traceable
and Finalizer
for your type and you now have GC object!
extern crate cgc_single_threaded as cgc;
use cgc::api::*;
// Simple linked list.
#[derive(Debug)]
struct Foo(Option<Handle<Foo>>);
impl Traceable for Foo {
fn trace_with(&self, tracer: &mut Tracer) {
self.0.trace_with(tracer);
}
}
impl Finalizer for Foo {
fn finalize(&mut self) {
println!("GCed");
}
}
fn main() {
let mut heap = cgc::heap::Heap::new(1024, 2048); // 1kb new space,2kb old space.
{
let value = heap.allocate(Foo(None));
let value2 = heap.allocate(Foo(Some(value.to_heap())));
println!("{:?}", value2);
}
heap.collect(); // value and value2 is GCed.
}