Trait rquickjs::allocator::Allocator

source ·
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 atleast size bytes and aligned to the size of usize.
  • realloc must either return a null pointer or return a pointer to an available region of memory atleast new_size bytes and aligned to the size of usize.
  • usable_size must return the amount of available memory for any allocation allocated with this allocator.

Required Methods§

source

fn alloc(&mut self, size: usize) -> *mut u8

Allocate new memory

source

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.

source

unsafe fn realloc(&mut self, ptr: *mut u8, new_size: usize) -> *mut u8

Re-allocate previously allocated memory

§Safety

Caller must ensure that the pointer points to an allocation that was allocated by the same Allocator instance.

source

unsafe fn usable_size(ptr: *mut u8) -> usize
where Self: Sized,

Get usable size of allocated memory region

§Safety

Caller must ensure that the pointer handed to this function points to an allocation allocated by the same allocator instance.

Implementors§