15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
- //! Utilities that help with tracking of memory allocations.
18
+ //! [`VecAllocExt`] and [`RawTableAllocExt`] to help tracking of memory allocations
19
19
20
20
use hashbrown:: raw:: { Bucket , RawTable } ;
21
21
@@ -24,12 +24,18 @@ pub trait VecAllocExt {
24
24
/// Item type.
25
25
type T ;
26
26
27
- /// [Push](Vec::push) new element to vector and store additional allocated bytes in `accounting` (additive).
27
+ /// [Push](Vec::push) new element to vector and increase
28
+ /// `accounting` by any newly allocated bytes.
29
+ ///
30
+ /// Note that allocation counts capacity, not size
28
31
fn push_accounted ( & mut self , x : Self :: T , accounting : & mut usize ) ;
29
32
30
- /// Return the amount of memory allocated by this Vec (not
31
- /// recursively counting any heap allocations contained within the
32
- /// structure). Does not include the size of `self`
33
+ /// Return the amount of memory allocated by this Vec to store elements
34
+ /// (`size_of<T> * capacity`).
35
+ ///
36
+ /// Note this calculation is not recursive, and does not include any heap
37
+ /// allocations contained within the Vec's elements. Does not include the
38
+ /// size of `self`
33
39
fn allocated_size ( & self ) -> usize ;
34
40
}
35
41
@@ -54,12 +60,15 @@ impl<T> VecAllocExt for Vec<T> {
54
60
}
55
61
}
56
62
57
- /// Extension trait for [`RawTable`] to account for allocations.
63
+ /// Extension trait for hash browns [`RawTable`] to account for allocations.
58
64
pub trait RawTableAllocExt {
59
65
/// Item type.
60
66
type T ;
61
67
62
- /// [Insert](RawTable::insert) new element into table and store additional allocated bytes in `accounting` (additive).
68
+ /// [Insert](RawTable::insert) new element into table and increase
69
+ /// `accounting` by any newly allocated bytes.
70
+ ///
71
+ /// Returns the bucket where the element was inserted.
63
72
fn insert_accounted (
64
73
& mut self ,
65
74
x : Self :: T ,
0 commit comments