Crates.io | tinypointers |
lib.rs | tinypointers |
version | 0.2.2 |
source | src |
created_at | 2023-12-03 19:49:10.675401 |
updated_at | 2023-12-05 02:58:25.553368 |
description | Pointer implementations that take 8 or 16 bits. |
homepage | |
repository | |
max_upload_size | |
id | 1057055 |
size | 20,042 |
This crate implements pointer types that take less space than the std
equivalents. You can choose between 8 or 16-bit using the flags 1byteid
and 2byteid
respectively.
[TinyBox
], [TinyArc
] and [TinyPtr
] are equivalent to Box
, Arc
and *mut T
,respectively.
Some care has been taken to ensure it's a mostly painless transition from rust
types to the equivalent tinypointers
type. Feel free to open a PR if functionality you need is missing!
To accomplish this, memory is allocated on the heap and inserted into a global array. You're given an index inside the array, and this is what is called an id
.
Since this crate strives to minimize memory footprint, NonZero*
are used internally to enable memory layout optimizations. This means both structs have the same size in the following example:
use tinypointers::TinyBox;
struct Bar(TinyBox<i32>);
struct Foo(Option<TinyBox<i32>>);
// 2 == 2
assert_eq!(std::mem::size_of::<Bar>(), std::mem::size_of::<Foo>())