pub unsafe trait Allocator {
// Required methods
fn alloc(&mut self, size: usize) -> *mut u8;
fn calloc(&mut self, count: usize, size: usize) -> *mut u8;
unsafe fn dealloc(&mut self, ptr: *mut u8);
unsafe fn realloc(&mut self, ptr: *mut u8, new_size: usize) -> *mut u8;
unsafe fn usable_size(ptr: *mut u8) -> usize
where Self: Sized;
}Expand description
The allocator interface
§Safety
Failure to implement this trait correctly will result in undefined behavior.
allocmust return a either a null pointer or a pointer to an available region of memory atleastsizebytes and aligned to the size ofusize.reallocmust either return a null pointer or return a pointer to an available region of memory atleastnew_sizebytes and aligned to the size ofusize.usable_sizemust return the amount of available memory for any allocation allocated with this allocator.
Required Methods§
Sourcefn calloc(&mut self, count: usize, size: usize) -> *mut u8
fn calloc(&mut self, count: usize, size: usize) -> *mut u8
Allocates memory for an array of num objects of size and initializes all bytes in the allocated storage to zero.
Sourceunsafe fn dealloc(&mut self, ptr: *mut u8)
unsafe fn dealloc(&mut self, ptr: *mut u8)
De-allocate previously allocated memory
§Safety
Caller must ensure that the pointer that is being deallocated was allocated by the same Allocator instance.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".