We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0dc380d commit 8d118e4Copy full SHA for 8d118e4
src/lib.rs
@@ -62,6 +62,14 @@ unsafe impl GlobalAlloc for MiMalloc {
62
}
63
64
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
+
73
#[cfg(test)]
74
mod tests {
75
use super::*;
@@ -133,4 +141,17 @@ mod tests {
133
141
alloc.dealloc(ptr, layout);
134
142
135
143
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
136
157
0 commit comments