lifeguard

Object Pool Manager
lifeguard issues owned values wrapped in smartpointers.
extern crate lifeguard;
use Pool;
//...
let pool : = with_size;
// Values that have gone out of scope are automatically moved back into the pool.
assert_eq!;
Values taken from the pool can be dereferenced to access/mutate their contents.
extern crate lifeguard;
use Pool;
//...
let mut pool : = with_size;
let mut string = pool.new_from;
.push_str;
assert_eq!;
Values can be unwrapped, detaching them from the pool.
let mut pool : = with_size;
// The String goes out of scope and is dropped; it is not returned to the pool
assert_eq!;
Values can be manually entered into / returned to the pool.
let mut pool : = with_size;
// The String is owned by the pool now
assert_eq!;
Highly Unscientific Benchmarks
Benchmark source can be found here. Tests were run on a VirtualBox VM with 3 CPUs @ 3Ghz and 4GB of RAM.
| Test Description | Allocating Normally | Using Object Pool | Improvement |
|---|---|---|---|
| String Allocation(String::with_capacity vs Pool::new) | 14379471 ns/iter(+/- 939144) | 8100463 ns/iter(+/- 208630) | ~43.67% |
| String Duplication(String::to_owned vs Pool::new_from) | 22243887 ns/iter(+/- 1251080) | 17502346 ns/iter(+/- 1086291) | ~21.32% |
| Creating a <Vec<Vec<String>>> | 1277138 ns/iter(+/- 114681) | 727415 ns/iter(+/- 62881) | ~43.04% |
Ideas and PRs welcome!
Inspired by frankmcsherry's recycler.