Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jkelleyrtp/bumpslab
A slab allocator with stable references
https://github.com/jkelleyrtp/bumpslab
Last synced: 19 days ago
JSON representation
A slab allocator with stable references
- Host: GitHub
- URL: https://github.com/jkelleyrtp/bumpslab
- Owner: jkelleyrtp
- Created: 2022-11-08T22:43:21.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T19:43:46.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T20:37:27.411Z (about 1 month ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BumpSlab: A bump allocator with reusable slots
[![crates.io](https://img.shields.io/crates/v/bumpslab.svg)](https://crates.io/crates/bumpslab)
A bumpslab is a slab that provides stable references for items inside the collection.
Normally, when a vec grows, its items will move around. Bumpslab is an arena allocator that gives you the pointer, not the key. This lets you chase down the pointer contents without the arena required to use the value. This means the pointer is guaranteed stable for the lifetime of the `Slot<>`
## Example
```rust
struct MyThing(usize);let slab = BumpSlab::new();
let a = slab.push(MyThing(0));
let b = slab.push(MyThing(1));
let c = slab.push(MyThing(2));let last = slab.push(MyThing(3));
let ptr = last.ptr();
slab.remove(last);let new_last = slab.push(Mything(4));
let new_ptr = new_last.ptr();// Slots get reused, known by pointer
assert_eq!(ptr, new_ptr);
```## When to use BumpSlab:
- you need stable references (ie driving futures without Arc for waker)
- you have only one type
- iteration is less important to you than lookups## Use as an Arc alternative:
The primary motivation for this crate was to enable spawning batches of futures without requiring Arc for the custom waker code. Wakers require a stable reference, typically guaranteed by Arc. However, if you're spawning many futures, this could come with some allocation overhead. BumpSlab gives you a stable reference for the lifetime of the waker and reuses slots as they are freed, keeping superior cache locality when compared to Arc.