@@ -59,6 +59,14 @@ impl Heap {
59
59
60
60
/// Initializes an empty heap
61
61
///
62
+ /// The `heap_bottom` pointer is automatically aligned, so the [`bottom()`][Self::bottom]
63
+ /// method might return a pointer that is larger than `heap_bottom` after construction.
64
+ ///
65
+ /// The given `heap_size` must be large enough to store the required
66
+ /// metadata, otherwise this function will panic. Depending on the
67
+ /// alignment of the `hole_addr` pointer, the minimum size is between
68
+ /// `2 * size_of::<usize>` and `3 * size_of::<usize>`.
69
+ ///
62
70
/// # Safety
63
71
///
64
72
/// This function must be called at most once and must only be used on an
@@ -82,13 +90,17 @@ impl Heap {
82
90
/// program's memory, from a mutable static, or by allocating and leaking such memory from
83
91
/// another allocator.
84
92
///
85
- /// The latter method may be especially useful if the underlying allocator does not perform
93
+ /// The latter approach may be especially useful if the underlying allocator does not perform
86
94
/// deallocation (e.g. a simple bump allocator). Then the overlaid linked-list-allocator can
87
95
/// provide memory reclamation.
88
96
///
89
97
/// # Panics
90
98
///
91
99
/// This method panics if the heap is already initialized.
100
+ ///
101
+ /// It also panics when the length of the given `mem` slice is not large enough to
102
+ /// store the required metadata. Depending on the alignment of the slice, the minimum
103
+ /// size is between `2 * size_of::<usize>` and `3 * size_of::<usize>`.
92
104
pub fn init_from_slice ( & mut self , mem : & ' static mut [ MaybeUninit < u8 > ] ) {
93
105
assert ! (
94
106
self . bottom( ) . is_null( ) ,
@@ -106,6 +118,14 @@ impl Heap {
106
118
107
119
/// Creates a new heap with the given `bottom` and `size`.
108
120
///
121
+ /// The `heap_bottom` pointer is automatically aligned, so the [`bottom()`][Self::bottom]
122
+ /// method might return a pointer that is larger than `heap_bottom` after construction.
123
+ ///
124
+ /// The given `heap_size` must be large enough to store the required
125
+ /// metadata, otherwise this function will panic. Depending on the
126
+ /// alignment of the `hole_addr` pointer, the minimum size is between
127
+ /// `2 * size_of::<usize>` and `3 * size_of::<usize>`.
128
+ ///
109
129
/// # Safety
110
130
///
111
131
/// The bottom address must be valid and the memory in the
@@ -123,8 +143,9 @@ impl Heap {
123
143
124
144
/// Creates a new heap from a slice of raw memory.
125
145
///
126
- /// This has the same effect as [`init_from_slice`] on an empty heap, but it is combined into a
127
- /// single operation that can not panic.
146
+ /// This is a convenience function that has the same effect as calling
147
+ /// [`init_from_slice`] on an empty heap. All the requirements of `init_from_slice`
148
+ /// apply to this function as well.
128
149
pub fn from_slice ( mem : & ' static mut [ MaybeUninit < u8 > ] ) -> Heap {
129
150
let size = mem. len ( ) ;
130
151
let address = mem. as_mut_ptr ( ) . cast ( ) ;
@@ -168,6 +189,9 @@ impl Heap {
168
189
}
169
190
170
191
/// Returns the bottom address of the heap.
192
+ ///
193
+ /// The bottom pointer is automatically aligned, so the returned pointer
194
+ /// might be larger than the bottom pointer used for initialization.
171
195
pub fn bottom ( & self ) -> * mut u8 {
172
196
self . holes . bottom
173
197
}
@@ -282,6 +306,14 @@ impl LockedHeap {
282
306
283
307
/// Creates a new heap with the given `bottom` and `size`.
284
308
///
309
+ /// The `heap_bottom` pointer is automatically aligned, so the [`bottom()`][Heap::bottom]
310
+ /// method might return a pointer that is larger than `heap_bottom` after construction.
311
+ ///
312
+ /// The given `heap_size` must be large enough to store the required
313
+ /// metadata, otherwise this function will panic. Depending on the
314
+ /// alignment of the `hole_addr` pointer, the minimum size is between
315
+ /// `2 * size_of::<usize>` and `3 * size_of::<usize>`.
316
+ ///
285
317
/// # Safety
286
318
///
287
319
/// The bottom address must be valid and the memory in the
0 commit comments