bytemuck::allocation

Function try_zeroed_slice_box

source
pub fn try_zeroed_slice_box<T: Zeroable>(length: usize) -> Result<Box<[T]>, ()>
Expand description

Allocates a Box<[T]> with all contents being zeroed out.

This uses the global allocator to create a zeroed allocation and then turns it into a Box. In other words, it’s 100% assured that the zeroed data won’t be put temporarily on the stack. You can make a box of any size without fear of a stack overflow.

§Failure

This fails if the allocation fails, or if a layout cannot be calculated for the allocation.