Skip to content

Commit

Permalink
exposing
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Dec 31, 2023
1 parent 0dc380d commit 8d118e4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ unsafe impl GlobalAlloc for MiMalloc {
}
}

impl MiMalloc {
#[allow(dead_code)]
#[inline]
unsafe fn usable_size(&self, ptr: *const u8) -> usize {
mi_usable_size(ptr as *const c_void)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -133,4 +141,17 @@ mod tests {
alloc.dealloc(ptr, layout);
}
}

#[test]
fn it_usable_size() {
unsafe {
let layout = Layout::from_size_align(8, 8).unwrap();
let alloc = MiMalloc;

let ptr = alloc.alloc(layout);
let usable_size = alloc.usable_size(ptr);
alloc.dealloc(ptr, layout);
assert!(usable_size >= 8);
}
}
}

0 comments on commit 8d118e4

Please sign in to comment.