I am trying to initialize a large array with shape [[u64; 4096]; 64]
. When I try to initialize this array with [[0; 4096]; 64]
I get different results depending on how the program is run.
When I run with cargo test
I get the following error:
thread '' has overflowed its stack
fatal runtime error: stack overflow
When I run with either cargo run
or cargo test --release
my program runs as expected. I think this means that the stack is simply not big enough to handle 8 * 64 * 4096 bytes (just over a MB), and that when I run in release or with cargo run
a different sized stack is allocated for the program.
- Is my assumption about running out of stack correct?
- Could I allocate the array to the heap within a
Box
instead? - Is this the best option?
I would really like look ups for this array to be as fast as possible.