Crates.io | mlsp |
lib.rs | mlsp |
version | 0.2.0 |
source | src |
created_at | 2021-12-18 01:04:24.844558 |
updated_at | 2021-12-18 19:56:37.668444 |
description | Mlsp is a small library for smart pointers that use both thread local and global atomic counters |
homepage | |
repository | https://github.com/Kylebrown9/mlsp |
max_upload_size | |
id | 499875 |
size | 16,065 |
The Multi-Level Smart Pointer uses an atomic global reference counter and per-thread non-atomic reference counters. The goal is that an MLSP should outperform a purely-atomicly counted smart pointer when enough local copies are performed.
The Mlsp
type can be used like Rc
for sharing memory within one thread.
It does not implement Send
and cannot be sent between threads, so any clone()
and drop()
operations performed on it use the local counter (except the last drop in a given thread).
The benefit of an Mlsp
over an Rc
is that repackaging it to share it with another thread does not require copying or moving the underlying data, it is already being stored in a way and with a counter that can be used to share between threads.
To send an Mlsp
to another thread, you must make an MlspPackage
.
The MlspPackage
type does implement Send
and is ready to be sent to other threads.
Receiving threads then use to create a new Mlsp
with its own local reference counter.
let a = Mlsp::new(1u8).package();
thread::spawn(move || {
let a2 = a; // Valid because MlspPackage implements Send
println!("{:?}", a.unpackage().borrow());
})
This library is still in need of extensive benchmarking and testing to demonstrate that it is robust and effective.