mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 18:12:51 +00:00
Add documents for DLMALLOC
This commit is contained in:
parent
eed45107da
commit
de87ae7961
@ -24,28 +24,32 @@ static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
|
||||
unsafe impl GlobalAlloc for System {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
// SAFETY: DLMALLOC.malloc() is guranteed to be safe since lock::lock() aqcuire a globl lock
|
||||
// SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
|
||||
// Calling malloc() is safe because preconditions on this function match the trait method preconditions.
|
||||
let _lock = lock::lock();
|
||||
unsafe { DLMALLOC.malloc(layout.size(), layout.align()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
// SAFETY: DLMALLOC.calloc() is guranteed to be safe since lock::lock() aqcuire a globl lock
|
||||
// SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
|
||||
// Calling calloc() is safe because preconditions on this function match the trait method preconditions.
|
||||
let _lock = lock::lock();
|
||||
unsafe { DLMALLOC.calloc(layout.size(), layout.align()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
// SAFETY: DLMALLOC.free() is guranteed to be safe since lock::lock() aqcuire a globl lock
|
||||
// SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
|
||||
// Calling free() is safe because preconditions on this function match the trait method preconditions.
|
||||
let _lock = lock::lock();
|
||||
unsafe { DLMALLOC.free(ptr, layout.size(), layout.align()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
// SAFETY: DLMALLOC.realloc() is guranteed to be safe since lock::lock() aqcuire a globl lock
|
||||
// SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
|
||||
// Calling realloc() is safe because preconditions on this function match the trait method preconditions.
|
||||
let _lock = lock::lock();
|
||||
unsafe { DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size) }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user