Struct sc_allocator::FreeingBumpHeapAllocator
source · pub struct FreeingBumpHeapAllocator { /* private fields */ }
Expand description
An implementation of freeing bump allocator.
Refer to the module-level documentation for further details.
Implementations§
source§impl FreeingBumpHeapAllocator
impl FreeingBumpHeapAllocator
sourcepub fn new(heap_base: u32) -> Self
pub fn new(heap_base: u32) -> Self
Creates a new allocation heap which follows a freeing-bump strategy.
Arguments
heap_base
- the offset from the beginning of the linear memory where the heap starts.
sourcepub fn allocate(
&mut self,
mem: &mut impl Memory,
size: WordSize
) -> Result<Pointer<u8>, Error>
pub fn allocate( &mut self, mem: &mut impl Memory, size: WordSize ) -> Result<Pointer<u8>, Error>
Gets requested number of bytes to allocate and returns a pointer. The maximum size which can be allocated at once is 32 MiB. There is no minimum size, but whatever size is passed into this function is rounded to the next power of two. If the requested size is below 8 bytes it will be rounded up to 8 bytes.
The identity or the type of the passed memory object does not matter. However, the size of memory cannot shrink compared to the memory passed in previous invocations.
NOTE: Once the allocator has returned an error all subsequent requests will return an error.
Arguments
mem
- a slice representing the linear memory on which this allocator operates.size
- size in bytes of the allocation request
sourcepub fn deallocate(
&mut self,
mem: &mut impl Memory,
ptr: Pointer<u8>
) -> Result<(), Error>
pub fn deallocate( &mut self, mem: &mut impl Memory, ptr: Pointer<u8> ) -> Result<(), Error>
Deallocates the space which was allocated for a pointer.
The identity or the type of the passed memory object does not matter. However, the size of memory cannot shrink compared to the memory passed in previous invocations.
NOTE: Once the allocator has returned an error all subsequent requests will return an error.
Arguments
mem
- a slice representing the linear memory on which this allocator operates.ptr
- pointer to the allocated chunk
sourcepub fn stats(&self) -> AllocationStats
pub fn stats(&self) -> AllocationStats
Returns the allocation stats for this allocator.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for FreeingBumpHeapAllocator
impl Send for FreeingBumpHeapAllocator
impl Sync for FreeingBumpHeapAllocator
impl Unpin for FreeingBumpHeapAllocator
impl UnwindSafe for FreeingBumpHeapAllocator
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,
source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.