I have the following code to read from a file:
let mut buf: Box<[u8]> = Box::new([0; 1024 * 1024]);
while let Ok(n) = f.read(&mut buf) {
if n > 0 {
resp.send_data(&buf[0..n]);
} else {
break;
}
}
But it causes:
fatal runtime error: stack overflow
I am on OS X 10.11 with Rust 1.12.0.
As Matthieu said,
Box::new([0; 1024 * 1024])
will currently overflow the stack due to initial stack allocation. If you are using Rust Nightly, thebox_syntax
feature will allow it to run without issues:You can find additional information about the difference between
box
andBox::new()
in the following question: What the difference is between using the box keyword and Box::new?.