Skip to content

Commit 42d63e3

Browse files
committed
Update lib.rs docs
Signed-off-by: Nico Burns <[email protected]>
1 parent e220b2f commit 42d63e3

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

malloc_size_of/src/lib.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! A crate for measuring the heap usage of data structures in a way that
12-
//! integrates with Firefox's memory reporting, particularly the use of
13-
//! mozjemalloc and DMD. In particular, it has the following features.
11+
//! A an allocator-agnostic crate for measuring the runtime size of a value
12+
//! including the size of any heap allocations that are owned by that value.
13+
//!
14+
//! - The core abstraction is provided by the [`MallocSizeOf`] trait which should be implemented for all
15+
//! types whose size you wish to measure.
16+
//! - A derive macro for implementing this trait on structs is provided by the [malloc_size_of_derive](https://docs.rs/malloc_size_of_derive) crate
17+
//! - Additionally there are [`MallocUnconditionalSizeOf`], [`MallocConditionalSizeOf`] traits for measuring
18+
//! types where ownership is shared (such as `Arc` and `Rc`).
19+
//! - Each of these traits also has a "shallow" variant ([`MallocShallowSizeOf`], [`MallocUnconditionalShallowSizeOf`], and [`MallocConditionalShallowSizeOf`]) which only measure the heap size of the value passed
20+
//! and not any nested allocations.
21+
//!
22+
//! All of these traits rely on being provided with an instance of [`MallocSizeOfOps`] which allows size computations
23+
//! to call into the allocator to ask it for the underlyinhg size of the allocations backing data structures.
24+
//!
25+
//! This crate is used by both Servo and Firefox for memory usage calculation.
26+
//!
27+
//! ## Features
28+
//!
1429
//! - It isn't bound to a particular heap allocator.
1530
//! - It provides traits for both "shallow" and "deep" measurement, which gives
1631
//! flexibility in the cases where the traits can't be used.
1732
//! - It allows for measuring blocks even when only an interior pointer can be
1833
//! obtained for heap allocations, e.g. `HashSet` and `HashMap`. (This relies
19-
//! on the heap allocator having suitable support, which mozjemalloc has.)
34+
//! on the heap allocator having suitable support, which `jemalloc` has.)
2035
//! - It allows handling of types like `Rc` and `Arc` by providing traits that
2136
//! are different to the ones for non-graph structures.
2237
//!
23-
//! Suggested uses are as follows.
38+
//! ## Suggested usage
39+
//!
2440
//! - When possible, use the `MallocSizeOf` trait. (Deriving support is
2541
//! provided by the `malloc_size_of_derive` crate.)
2642
//! - If you need an additional synchronization argument, provide a function
@@ -42,9 +58,6 @@
4258
//! fields in structs, because it makes it clear that the Box is being
4359
//! measured as well as the thing it points to. E.g.
4460
//! `<Box<_> as MallocSizeOf>::size_of(field, ops)`.
45-
//!
46-
//! Note: WebRender has a reduced fork of this crate, so that we can avoid
47-
//! publishing this crate on crates.io.
4861
#![cfg_attr(not(feature = "std"), no_std)]
4962
extern crate alloc;
5063
mod impls;

0 commit comments

Comments
 (0)