Crates.io | shared_hashmap |
lib.rs | shared_hashmap |
version | 0.1.2 |
source | src |
created_at | 2023-06-24 08:41:59.422727 |
updated_at | 2023-10-03 13:23:29.762263 |
description | A shared hashmap for use between processes, using shared memory |
homepage | |
repository | https://github.com/humanmade/shared_hashmap/ |
max_upload_size | |
id | 898852 |
size | 28,596 |
A shared memory hashmap including LRU eviction.
This crate provides a shared hashmap limited by memory size that can be used between difference processes and thread. This is achieved by using the shared_memory crate and raw_sync-rs for IPC mutexes.
The SharedMemoryHashMap
internally handles locking and serializing of Keys and Values in an optimized memory layout. Current the LRU implementation is basic, using timestamps for access rather than an ordered key-list. Implementing a key-list for LRU purposes is possible but requires more manual memory management.
use shared_memory_hashmap::SharedMemoryHashMap;
fn main() {
let mut map = SharedMemoryHashMap::new(1024); // bytes.
map.insert(1, "Hello");
map.insert(2, "World");
map2 = map.clone(); // map2 uses the same shared memory block as `map`.
spawn(|| move {
map2.insert(3, "Goodbye");
});
}