get-size2
Determine the size in bytes an object occupies inside RAM.
size_of already reports how many bytes a value occupies on the stack. Applications like caches or memory budgets also need to know how many bytes a value owns on the heap, which is what the GetSize trait adds.
This crate is a fork of get-size, which is no longer maintained.
Usage
[]
= { = "^0.10", = ["derive"] }
use GetSize;
let data = Data ;
assert_eq!;
assert_eq!;
Only bytes owned by a value are counted, so anything merely borrowed through a reference counts as zero. Shared ownership (Rc, Arc) is counted once, deduplicated by a tracker.
Features
std is enabled by default and implies alloc; disable both for no_std targets:
= { = "^0.10", = false, = ["alloc", "derive"] }
| Feature | Description |
|---|---|
std (default) |
Implementations for std types like HashMap, PathBuf or Mutex |
alloc |
Implementations for alloc types like Vec, String, Box, Rc and Arc |
derive |
The #[derive(GetSize)] macro |
all-features-no-std |
Every feature which works without std |
Implementations for third party types are available behind the bytes, chrono, chrono-tz, compact-str, dashmap, half, hashbrown, indexmap, ordermap, orx-concurrent-vec, parking_lot, portable-atomic, roaring, smallvec, thin-vec and url features. dashmap and parking_lot require std.
Documentation
The full guide is on docs.rs: the ownership model and its pitfalls, tracking shared ownership, no_std support, deriving and implementing the trait, and what the reported sizes do and do not include. The derive attributes are documented in get-size-derive2.
License
This library is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this library by you shall be licensed as MIT, without any additional terms or conditions.