#shared-memory #hash-map #ipc #process #memory-size #memory-layout

shared_hashmap

A shared hashmap for use between processes, using shared memory

3 releases

0.1.2 Oct 3, 2023
0.1.1 Jun 24, 2023
0.1.0 Jun 24, 2023

#223 in Memory management

32 downloads per month

MIT/Apache

22KB
414 lines

Shared HashMap

Continuous integration

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.

Usage

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");
    });
}

Dependencies

~2–29MB
~392K SLoC