pub unsafe trait Allocator {
// Required methods
fn alloc(&mut self, 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;
}
Available on crate feature
allocator
only.Expand description
The allocator interface
§Safety
Failure to implement this trait correctly will result in undefined behavior.
alloc
must return a either a null pointer or a pointer to an available region of memory atleastsize
bytes and aligned to the size ofusize
.realloc
must either return a null pointer or return a pointer to an available region of memory atleastnew_size
bytes and aligned to the size ofusize
.usable_size
must return the amount of available memory for any allocation allocated with this allocator.
Required Methods§
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.