diff --git a/src/lib.rs b/src/lib.rs index 657766b..d1e376d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,6 +162,18 @@ unsafe impl<'a> Alloc for &'a Jemalloc { } } + #[inline] + unsafe fn alloc_excess(&mut self, layout: Layout) -> Result { + let flags = align_to_flags(layout.align()); + let ptr = ffi::mallocx(layout.size(), flags); + if ptr.is_null() { + Err(AllocErr::Exhausted { request: layout }) + } else { + let excess = ffi::nallocx(layout.size(), flags); + Ok(Excess(ptr as *mut u8, excess)) + } + } + #[inline] unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) { let flags = align_to_flags(layout.align(), layout.size()); @@ -185,6 +197,24 @@ unsafe impl<'a> Alloc for &'a Jemalloc { } } + #[inline] + unsafe fn realloc_excess(&mut self, + ptr: *mut u8, + old_layout: Layout, + new_layout: Layout) -> Result { + if old_layout.align() != new_layout.align() { + return Err(AllocErr::Unsupported { details: "cannot change align" }) + } + let flags = align_to_flags(new_layout.align()); + let ptr = ffi::rallocx(ptr as *mut c_void, new_layout.size(), flags); + if ptr.is_null() { + Err(AllocErr::Exhausted { request: new_layout }) + } else { + let excess = ffi::nallocx(new_layout.size(), flags); + Ok(Excess(ptr as *mut u8, excess)) + } + } + fn oom(&mut self, err: AllocErr) -> ! { System.oom(err) }