A WebAssembly slab allocator for external references.
- Rust 76.2%
- WebAssembly 23.8%
| tests | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
| table-slab.wat | ||
WASM Table Slab
A slab allocator for external references. It can be used to convert from externref to i32
such that it can be used by languages which don't support externref.
Assembling
Use wasm-tools to assemble.
wasm-tools parse -o table-slab.wasm table-slab.wat
How it works
The library uses an anyref table, which initially only contains the null reference at index 0.
A the $next global is the index of a free index or after the last element if the table is full.
When an item is removed, it is replaced by an i31 pointing to the current $next, and
$next is updated to point to the removed item.
This way, the i31 "tombstones" form a linked list of vacant items enabling O(1) alloc and free.