| 1 | # memuse |
| 2 | |
| 3 | This crate contains traits for measuring the dynamic memory usage of Rust types. |
| 4 | |
| 5 | ## About |
| 6 | |
| 7 | Memory-tracking is a common activity in large applications, particularly ones |
| 8 | that receive data from a network and store it in memory. By monitoring how much |
| 9 | memory is used by different areas of the application, memory pressure can be |
| 10 | alleviated by ignoring new packets, or implementing random drop logic for DoS |
| 11 | mitigation. |
| 12 | |
| 13 | Measuring memory use on the stack is easy, with [`std::mem::size_of`] and |
| 14 | friends. Measuring memory allocated on the heap is more tricky. Applications can |
| 15 | use a custom global allocator to track the memory usage of different areas. This |
| 16 | isn't an option for reusable library code however, and the nearest alternative |
| 17 | (using custom allocators for individual types) is currently only an experimental |
| 18 | feature in nightly Rust ([`allocator_api`]). |
| 19 | |
| 20 | [`std::mem::size_of`]: https://doc.rust-lang.org/stable/std/mem/fn.size_of.html |
| 21 | [`allocator_api`]: https://github.com/rust-lang/rust/issues/32838 |
| 22 | |
| 23 | This crate takes a different approach: it provides traits that library authors |
| 24 | can use to expose dynamic memory usage information on their types. By composing |
| 25 | these implementations, we gain the ability to query the amount of heap-allocated |
| 26 | memory in use by specific instances of types at any point in time, without any |
| 27 | changes to the way in which these types are constructed. |
| 28 | |
| 29 | ## Minimum Supported Rust Version |
| 30 | |
| 31 | Rust **1.51** or newer. |
| 32 | |
| 33 | In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope |
| 34 | for this crate's SemVer guarantees), however when we do it will be accompanied |
| 35 | by a minor version bump. |
| 36 | |
| 37 | ## License |
| 38 | |
| 39 | Licensed under either of |
| 40 | |
| 41 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or |
| 42 | http://www.apache.org/licenses/LICENSE-2.0) |
| 43 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 44 | |
| 45 | at your option. |
| 46 | |
| 47 | ### Contribution |
| 48 | |
| 49 | Unless you explicitly state otherwise, any contribution intentionally |
| 50 | submitted for inclusion in the work by you, as defined in the Apache-2.0 |
| 51 | license, shall be dual licensed as above, without any additional terms or |
| 52 | conditions. |
| 53 |