Crates.io | rc_arena |
lib.rs | rc_arena |
version | 0.1.0 |
source | src |
created_at | 2015-08-29 23:41:07.04895 |
updated_at | 2015-12-11 23:55:29.371301 |
description | An arena which yields reference counted pointers to the underlying objects |
homepage | https://github.com/ebfull/rc_arena |
repository | https://github.com/ebfull/rc_arena |
max_upload_size | |
id | 2957 |
size | 8,356 |
Alternative to typed-arena that instead returns reference counted pointers
to the underlying objects, avoiding lifetime bounds but incurring a runtime penalty. Useful when you wish to create
a large number of Rc<T>
objects but want them close together in memory, or wish to avoid expensive allocations.
As with all arenas, it's also useful if you don't care about deallocation until after you're done with the entire collection of objects.
Cargo.toml:
[dependencies]
rc_arena = "0.1.0"
Code:
extern crate rc_arena;
use rc_arena::Arena;
fn main() {
let arena = Arena::new();
let foo = arena.alloc([1,2,3,4]);
let bar = arena.alloc([5,6,7,8]);
let baz = foo.clone();
assert_eq!(foo[0], 1);
assert_eq!(bar[0], 5);
assert_eq!(baz[0], 1);
}