Skip to content

Commit 4673f93

Browse files
Merge #37
37: Exposed `used` and `free` methods on CortexMHeap r=jonas-schievink a=VictorKoenders Added two methods that expose existing functions on the Heap: - https://docs.rs/linked_list_allocator/0.8.4/linked_list_allocator/struct.Heap.html#method.used - https://docs.rs/linked_list_allocator/0.8.4/linked_list_allocator/struct.Heap.html#method.free The functions should be generic enough that it doesn't pin alloc-cortex-m to a specific implementation. This is the reason the documentation mentions that the methods return an "estimate", as future implementations might not be accurate. Co-authored-by: Trangar <victor.koenders@gmail.com>
2 parents 6c9060f + dd70b4f commit 4673f93

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ impl CortexMHeap {
6161
.init(start_addr, size);
6262
});
6363
}
64+
65+
/// Returns an estimate of the amount of bytes in use.
66+
pub fn used(&self) -> usize {
67+
cortex_m::interrupt::free(|cs| {
68+
self.heap
69+
.borrow(cs)
70+
.borrow_mut()
71+
.used()
72+
})
73+
}
74+
75+
/// Returns an estimate of the amount of bytes available.
76+
pub fn free(&self) -> usize {
77+
cortex_m::interrupt::free(|cs| {
78+
self.heap
79+
.borrow(cs)
80+
.borrow_mut()
81+
.free()
82+
})
83+
}
6484
}
6585

6686
unsafe impl GlobalAlloc for CortexMHeap {

0 commit comments

Comments
 (0)