Struct static_alloc::leaked::Alloca
source · pub struct Alloca<T> { /* private fields */ }
Expand description
Zero-sized marker struct that allows running one or several methods.
This ensures that allocation does not exceed certain limits that would likely blow the stack and run into Rust’s canary, this aborting the process.
Implementations§
source§impl<T> Alloca<T>
impl<T> Alloca<T>
sourcepub fn new(len: usize) -> Option<Self>
pub fn new(len: usize) -> Option<Self>
Try to create a representation, that allows functions with dynamically stack-allocated slices.
sourcepub fn run<R>(&self, run: impl FnOnce(&mut [MaybeUninit<T>]) -> R) -> R
pub fn run<R>(&self, run: impl FnOnce(&mut [MaybeUninit<T>]) -> R) -> R
Allocate a slice of elements.
Please note that instantiating this method relies on the optimizer, to an extent. In
particular we will create stack slots of differing sizes depending on the internal size.
This shouldn’t have an effect other than moving the stack pointer for various amounts and
should never have more than one T
in overhead. However, we can’t enforce this. In theory
llvm might still reserve stack space for all variants including a probe and thus
prematurely assume we have hit the bottom of the available stack space. This is not very
likely to occur in practice.