| Crates.io | dense-slotmap-mem |
| lib.rs | dense-slotmap-mem |
| version | 0.1.1 |
| created_at | 2025-12-28 10:02:15.341465+00 |
| updated_at | 2025-12-29 19:01:02.97282+00 |
| description | Fixed-capacity, generation-tracked dense slot map with stable handles and raw memory interface, optimized for the Swamp VM |
| homepage | |
| repository | https://github.com/piot/dense-slotmap-mem |
| max_upload_size | |
| id | 2008532 |
| size | 42,671 |
A fixed-capacity, generation-tracked dense slot map with a raw memory interface, optimized for FFI, VM integration, and low-level systems (Game Engines). Should typically not be used in a normal Rust application.
A slot map is a data structure that provides stable "handles" (in this implementation: ID + generation) to elements. To make it more cache and iteration-friendly it uses swap-remove to keep all elements contiguous in memory.
*mut u8 pointers, not generic Rust typesno_std compatible - Works in embedded and bare-metal environmentsuse dense_slotmap_mem::{init, allocate, insert, remove, is_alive, layout_size};
unsafe {
let capacity = 100u16;
let element_size = 4u32; // e.g., for u32 values
let size = layout_size(capacity, element_size);
let mut memory = vec![0u8; size];
let base = memory.as_mut_ptr();
// Initialize the slot map
init(base, capacity, element_size);
// Allocate a slot and get a stable handle
let (id, generation) = allocate(base).unwrap();
// Insert data using the handle
let value = 42u32;
insert(base, id, generation, (&raw const value).cast::<u8>());
// Check if handle is still valid
assert!(is_alive(base, id, generation));
// Remove by handle - last element swaps into this slot
remove(base, id, generation);
// Old handle is now invalid
assert!(!is_alive(base, id, generation));
}
Licensed under the MIT License. See LICENSE for details.
Copyright (c) 2025 Peter Bjorklund. All Rights Reserved.