🪣 sparse-mem
Welcome to sparse-mem, a low-level memory layout implementation for
fixed-capacity, generation-tracked sparse arrays designed specifically for the
Swamp VM.
What is it?
This crate provides the raw memory layout and operations for a sparse array structure that:
- Works with fixed capacity (decided upfront)
- Tracks generations to prevent dangling references
- Follows the Swamp VM Collection standard
- Operates directly on raw memory pointers
Not a typical Rust collection
Important note: This is not a standard Rust collection! It's designed to work with raw memory layouts designed for VM internals. If you're looking for a more typical Rust sparse slot map implementation with all the Rust safety guarantees, check out my other crate:
👉 sparse-slot (github)
Usage
This is a low-level crate meant for VM implementers. You'll be working with raw pointers and unsafe code (living on the edge!):
use ptr;
// Allocate memory (you need to handle this part)
let capacity = 10;
let element_size = 4;
let total_size = layout_size;
let memory = vec!;
unsafe
Safety
Since this crate deals with direct raw memory manipulation, almost all functions
are unsafe. Use with caution! ⚠️
Why use this?
It probably only makes sense if you are:
- Implementing a VM with specific memory layout requirements
- Need precise control over memory allocation and layout
- Want a sparse array that follows the Swamp VM Collection standard.
About Contributions
This is an open source project with a single copyright holder. Even though the code is publicly available under LICENSE, I am not accepting external contributions at this time.
You are welcome to:
- Use the code according to the license terms
- Fork the project for your own use, following the license terms
- Report issues
- Provide feedback
- Share the project
If you have suggestions or find bugs, please feel free to open an issue for discussion. While I cannot accept pull requests, I value your feedback and engagement with the project.
Thank you for your understanding and interest in the project! 🙏
License
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2025 Peter Bjorklund. All rights reserved