Open
Description
This is possibly the same bug as
Using the latest version of Rust
rustc 1.27.2 (58cc626 2018-07-18)
The following code causes a stack overflow
#[test]
fn test_boxed() {
let a = Box::new([-1; 3000000]);
}
Workarounds
Using Vec<T>
This does not have overhead.
let boxed_slice: Box<[u8]> = vec![0; 100_000_000].into_boxed_slice();
let boxed_array: Box<[u8; 100_000_000]> = vec![0; 100_000_000].into_boxed_slice().try_into().unwrap();
Unstably using new_uninit
This requires an unstable API and unsafe, but is more flexible.
let mut b = Box::new_uninit();
unsafe { std::ptr::write_bytes(b.as_mut_ptr(), 0, 100_000_000) };
let boxed_array: Box<[u8; 100_000_000]> = unsafe { b.assume_init() };