Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diegovsky/tinypointers
https://github.com/diegovsky/tinypointers
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/diegovsky/tinypointers
- Owner: Diegovsky
- Created: 2023-12-03T19:42:53.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-05T02:58:17.000Z (about 1 year ago)
- Last Synced: 2024-10-15T22:08:27.069Z (2 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tiny Pointers
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!
## How
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`.## Size optimizations
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:
```rust
use tinypointers::TinyBox;struct Bar(TinyBox);
struct Foo(Option>);
// 2 == 2
assert_eq!(std::mem::size_of::(), std::mem::size_of::())```