Skip to main content

IHeap

Trait IHeap 

Source
pub trait IHeap<S: IShape> {
    type Ptr: IPtr;

    // Required methods
    unsafe fn alloc(&mut self, shape: S) -> Self::Ptr;
    unsafe fn dealloc(&mut self, ptr: Self::Ptr, shape: S);
    unsafe fn memcpy(&mut self, dst: Self::Ptr, src: Self::Ptr, len: usize);
    unsafe fn drop_in_place(&mut self, ptr: Self::Ptr, shape: S);
    unsafe fn default_in_place(&mut self, ptr: Self::Ptr, shape: S) -> bool;
}
Expand description

Heap for memory operations, generic over shape type.

Required Associated Types§

Source

type Ptr: IPtr

Pointer type used by this heap.

Required Methods§

Source

unsafe fn alloc(&mut self, shape: S) -> Self::Ptr

Allocate a region for a value of the given shape.

§Safety

The caller must ensure shape is valid for allocation and that any constraints required by the heap implementation are satisfied.

Source

unsafe fn dealloc(&mut self, ptr: Self::Ptr, shape: S)

Deallocate a region.

§Safety

The caller must ensure ptr points to the start of a live allocation previously returned by alloc, that the allocation corresponds to shape, and that no bytes in the region are still initialized.

Source

unsafe fn memcpy(&mut self, dst: Self::Ptr, src: Self::Ptr, len: usize)

Copy len bytes from src to dst.

§Safety

The caller must ensure both ranges are in-bounds for their allocations, that src is fully initialized, dst is fully uninitialized, and the ranges do not overlap.

Source

unsafe fn drop_in_place(&mut self, ptr: Self::Ptr, shape: S)

Drop the value at ptr and mark the range as uninitialized.

§Safety

The caller must ensure ptr points to a value of type shape, the value is fully initialized, and the allocation is still live.

Source

unsafe fn default_in_place(&mut self, ptr: Self::Ptr, shape: S) -> bool

Default-initialize the value at ptr and mark the range as initialized.

Returns false if the shape has no default.

§Safety

The caller must ensure the destination range is uninitialized, in-bounds, and corresponds to shape.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl IHeap<&'static Shape> for LHeap

Source§

impl<S: IShape> IHeap<S> for VHeap<S>