Trait rlsf::FlexSource

source ·
pub unsafe trait FlexSource {
    // Provided methods
    unsafe fn alloc(&mut self, min_size: usize) -> Option<NonNull<[u8]>> { ... }
    unsafe fn realloc_inplace_grow(
        &mut self,
        ptr: NonNull<[u8]>,
        min_new_len: usize
    ) -> Option<usize> { ... }
    unsafe fn dealloc(&mut self, ptr: NonNull<[u8]>) { ... }
    fn supports_dealloc(&self) -> bool { ... }
    fn supports_realloc_inplace_grow(&self) -> bool { ... }
    fn is_contiguous_growable(&self) -> bool { ... }
    fn min_align(&self) -> usize { ... }
}
Expand description

The trait for dynamic storage allocators that can back FlexTlsf.

Provided Methods§

source

unsafe fn alloc(&mut self, min_size: usize) -> Option<NonNull<[u8]>>

Allocate a memory block of the requested minimum size.

Returns the address range of the allocated memory block.

Safety

min_size must be a multiple of GRANULARITY. min_size must not be zero.

source

unsafe fn realloc_inplace_grow( &mut self, ptr: NonNull<[u8]>, min_new_len: usize ) -> Option<usize>

Attempt to grow the specified allocation without moving it. Returns the final allocation size (which must be greater than or equal to min_new_len) on success.

Safety

ptr must be an existing allocation made by this allocator. min_new_len must be greater than or equal to ptr.len().

source

unsafe fn dealloc(&mut self, ptr: NonNull<[u8]>)

Deallocate a previously allocated memory block.

Safety

ptr must denote an existing allocation made by this allocator.

source

fn supports_dealloc(&self) -> bool

Check if this allocator implements Self::dealloc.

If this method returns false, FlexTlsf will not call dealloc to release memory blocks. It also applies some optimizations.

The returned value must be constant for a particular instance of Self.

source

fn supports_realloc_inplace_grow(&self) -> bool

Check if this allocator implements Self::realloc_inplace_grow.

If this method returns false, FlexTlsf will not call realloc_inplace_grow to attempt to grow memory blocks. It also applies some optimizations.

The returned value must be constant for a particular instance of Self.

source

fn is_contiguous_growable(&self) -> bool

Returns true if this allocator is implemented by managing one contiguous region, which is grown every time alloc or realloc_inplace_grow is called.

For example, in WebAssembly, there is usually only one continuous memory region available for data processing, and the only way to acquire more memory is to grow this region by executing memory.grow instructions. An implementation of FlexSource based on this system would use this instruction to implement both alloc and realloc_inplace_grow methods. Therefore, it’s pointless for FlexTlsf to call alloc when realloc_inplace_grow fails. This method can be used to remove such redundant calls to alloc.

The returned value must be constant for a particular instance of Self.

source

fn min_align(&self) -> usize

Get the minimum alignment of allocations made by this allocator. FlexTlsf may be less efficient if this method returns a value less than GRANULARITY.

The returned value must be constant for a particular instance of Self.

Implementors§

source§

impl<T: GlobalAlloc, const ALIGN: usize> FlexSource for GlobalAllocAsFlexSource<T, ALIGN>