Skip to content

Commit 8d118e4

Browse files
committed
exposing
1 parent 0dc380d commit 8d118e4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ unsafe impl GlobalAlloc for MiMalloc {
6262
}
6363
}
6464

65+
impl MiMalloc {
66+
#[allow(dead_code)]
67+
#[inline]
68+
unsafe fn usable_size(&self, ptr: *const u8) -> usize {
69+
mi_usable_size(ptr as *const c_void)
70+
}
71+
}
72+
6573
#[cfg(test)]
6674
mod tests {
6775
use super::*;
@@ -133,4 +141,17 @@ mod tests {
133141
alloc.dealloc(ptr, layout);
134142
}
135143
}
144+
145+
#[test]
146+
fn it_usable_size() {
147+
unsafe {
148+
let layout = Layout::from_size_align(8, 8).unwrap();
149+
let alloc = MiMalloc;
150+
151+
let ptr = alloc.alloc(layout);
152+
let usable_size = alloc.usable_size(ptr);
153+
alloc.dealloc(ptr, layout);
154+
assert!(usable_size >= 8);
155+
}
156+
}
136157
}

0 commit comments

Comments
 (0)