pub unsafe fn raw_box_zeroed<T>() -> Box<T>Expand description
Similar to raw_box, this API creates a box structure without moving the wrapped value from the
stack to the heap. This API is most useful when the wrapped value is too large for the default
stack size, such that initializing and packing the valuing into the box is a pain.
The only difference is that all fields in the object will be initialized to 0. This will initialize
most primitive types, however, there is no warrant that the boxed object is valid or meaningful.
For example, if the source struct contains pointers or another Boxed object, the fields are still
undefined since they’re pointing to the null pointer (i.e. default pointer created by
std::ptr::null_mut()).
§Examples
Create a boxed DangerousStruct
use syncpool::raw_box_zeroed;
struct BigStruct {
a: u32,
b: u32,
c: [u8; 0x1_000_000],
}
// create the object on the heap directly
let mut big: Box<BigStruct> = unsafe { raw_box_zeroed::<BigStruct>() };
// the fields are now valid
assert_eq!(big.c.len(), 0x1_000_000);
assert_eq!(big.c[4200], 0);
assert_eq!(big.a, 0);