Skip to content

Commit 8aa1f64

Browse files
authored
Merge pull request #2 from japaric/init
add an initialize method to Heap
2 parents a71d6cb + 81600c3 commit 8aa1f64

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ impl Heap {
2929
}
3030
}
3131

32+
/// Initializes an empty heap
33+
///
34+
/// # Unsafety
35+
///
36+
/// This function must be called at most once and must only be used on an
37+
/// empty heap.
38+
pub unsafe fn init(&mut self, heap_bottom: usize, heap_size: usize) {
39+
self.bottom = heap_bottom;
40+
self.size = heap_size;
41+
self.holes = HoleList::new(heap_bottom, heap_size);
42+
}
43+
3244
/// Creates a new heap with the given `bottom` and `size`. The bottom address must be valid
3345
/// and the memory in the `[heap_bottom, heap_bottom + heap_size)` range must not be used for
3446
/// anything else. This function is unsafe because it can cause undefined behavior if the

0 commit comments

Comments
 (0)