Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huonw/boehm-rs
https://github.com/huonw/boehm-rs
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/huonw/boehm-rs
- Owner: huonw
- Created: 2014-01-01T15:15:12.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-09-21T12:15:13.000Z (about 8 years ago)
- Last Synced: 2023-04-10T09:38:34.003Z (over 1 year ago)
- Language: Rust
- Homepage: http://huonw.github.io/boehm-rs/boehm/
- Size: 479 KB
- Stars: 10
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Using the Boehm GC from Rust
[![Build Status](https://travis-ci.org/huonw/boehm-rs.png)](https://travis-ci.org/huonw/boehm-rs)
A basic wrapper that provides `Gc` and `GcTracing` types
(completely conservative and precise-on-heap respectively),
implemented by binding to the
[Boehm-Demers-Weiser garbage collector](http://www.hpl.hp.com/personal/Hans_Boehm/gc/). See
`examples/` for some examples.## Warning
This is not correct and shouldn't be used/should only be used very
carefully, because I don't think the Rust compiler provides enough
hooks yet to make something like `~[Gc]` completely work.To illustrate, the following program is trying to make a vector
`~[Gc 0, Gc 1, ..., Gc 1_000_000]`, so it should print `0`... but it
prints `895221` for me; the vector doesn't act as a root that Boehm
can understand, and so it's free to GC the first one and reuse that
memory for one of the later allocations. Oops.```rust
extern mod boehm;#[start]
fn main(_: int, _: **u8) -> int {
boehm::init();let mut v = std::vec::from_fn(1_000_000, boehm::Gc::new);
println!("{}", *v[0].borrow());0
}
```I think this could be somewhat fixed with some trickery with
`#[no_std]` and `#[lang="malloc"]` and so on, but that's beyond the
time I've been able to allocate (no pun intended) to this so far.## Todo
- Fix the above
- Stop generating the Boehm type-descriptor for each type on every
allocation (requires compiler support to do properly, but we could
cache based on the address of the (Rust) type descriptor, or
something)## Todo-done
- Use
[the typed inferface](http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc_typedh.txt)
for more precise collection (at the very least, working out a way to
use malloc_atomic where appropriate would be good). See [`boehm::tracing`](http://huonw.github.io/boehm-rs/boehm/tracing/index.html).## License
Dual Apache v2.0 and MIT, like Rust itself.