本文介绍了堆栈溢出在鲁斯特0.13大固定大小的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望与防锈专家核实这个简单的防锈程序(在Linux上的x86-64系统rustc 0.13.0-夜间):
I wish to verify with the Rust expert this simple Rust program (rustc 0.13.0-nightly on Linux x86-64 system):
/*
the runtime error is:
task '<main>' has overflowed its stack
Illegal instruction (core dumped)
*/
fn main() {
let l = [0u, ..1_000_000u];
}
编译过程没有错误完全结束,但在运行该程序失败,在code注释中显示的错误。
The compile process ends perfectly with no error but at runtime the program failed with the error shown in the code comment.
是否有固定大小的数组鲁斯特尺寸的限制,或这是一个错误的地方在编译器?
Is there a limit to the dimension of fixed size array in Rust or is this a bug somewhere in the compiler?
推荐答案
锈病2MiB的默认堆栈大小,你只是运行的堆栈空间:
Rust has a default stack size of 2MiB, you are just running out of stack space:
fn main() {
println!("min_stack = {}", std::rt::min_stack());
}
要分配该大小的数组必须使用其分配给堆箱
:
To allocate the array of that size you have to allocate it on the heap using box
:
fn main() {
let l = box [0u, ..1_000_000u];
}
这篇关于堆栈溢出在鲁斯特0.13大固定大小的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!