pub struct GrantRegionAllocator { /* private fields */ }
Expand description
Tool for allocating additional memory regions in a process’s grant region.
This is optionally provided along with a grant so that if a capsule needs per-process dynamic allocation it can allocate additional memory.
Implementations§
Source§impl GrantRegionAllocator
impl GrantRegionAllocator
Sourcepub fn alloc_with<T, F>(&self, init: F) -> Result<CustomGrant<T>, Error>where
F: FnOnce() -> T,
pub fn alloc_with<T, F>(&self, init: F) -> Result<CustomGrant<T>, Error>where
F: FnOnce() -> T,
Allocates a new CustomGrant
initialized using the given closure.
The closure will be called exactly once, and the result will be used to initialize the owned value.
This interface was chosen instead of a simple alloc(val)
as it’s
much more likely to optimize out all stack intermediates. This
helps to prevent stack overflows when allocating large values.
§Panic Safety
If init
panics, the freshly allocated memory may leak.
Sourcepub fn alloc_n_with<T, F, const NUM_ITEMS: usize>(
&self,
init: F,
) -> Result<CustomGrant<[T; NUM_ITEMS]>, Error>
pub fn alloc_n_with<T, F, const NUM_ITEMS: usize>( &self, init: F, ) -> Result<CustomGrant<[T; NUM_ITEMS]>, Error>
Allocates a slice of n instances of a given type. Each instance is initialized using the provided function.
The provided function will be called exactly n
times, and will be
passed the index it’s initializing, from 0
through NUM_ITEMS - 1
.
§Panic Safety
If val_func
panics, the freshly allocated memory and any values
already written will be leaked.