Trait rlsf::FlexSource [−][src]
pub unsafe trait FlexSource { 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
unsafe fn alloc(&mut self, min_size: usize) -> Option<NonNull<[u8]>>
[src]
unsafe fn alloc(&mut self, min_size: usize) -> Option<NonNull<[u8]>>
[src]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.
unsafe fn realloc_inplace_grow(
&mut self,
ptr: NonNull<[u8]>,
min_new_len: usize
) -> Option<usize>
[src]
unsafe fn realloc_inplace_grow(
&mut self,
ptr: NonNull<[u8]>,
min_new_len: usize
) -> Option<usize>
[src]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()
.
unsafe fn dealloc(&mut self, ptr: NonNull<[u8]>)
[src]
unsafe fn dealloc(&mut self, ptr: NonNull<[u8]>)
[src]Deallocate a previously allocated memory block.
Safety
ptr
must denote an existing allocation made by this allocator.
fn supports_dealloc(&self) -> bool
[src]
fn supports_dealloc(&self) -> bool
[src]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
.
fn supports_realloc_inplace_grow(&self) -> bool
[src]
fn supports_realloc_inplace_grow(&self) -> bool
[src]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
.
fn is_contiguous_growable(&self) -> bool
[src]
fn is_contiguous_growable(&self) -> bool
[src]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
.
fn min_align(&self) -> usize
[src]
fn min_align(&self) -> usize
[src]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
.