The arr crate is a simple fixed size array designed to allow huge array allocation without stack overflows.
Even in rustc 1.44 allocating arrays too large to fit on the stack (say 8MB in size) will stack overflow even if the array is Boxed.
use arr::Array; // zero - fast allocation let big_array: Array<u8> = Array::zero(1 << 25); // default - slow allocation let big_array2: Array<u8> = Array::new(1 << 25); // template let template = 10u8; let big_array3: Array<u8> = Array::new_from_template(1 << 25, &template); // Also works for 2d arrays (note even the sub-array would ordinarily blow stack) let big_2d_array: Array<[u8; 1 << 25]> = Array::zero(4);
Try to do this with a traditional array:
let big_array: Box<[u8; 1 << 25]> = Box::new([0u8; 1 << 25]);
Currently the array supports three modes of allocation, via
new (requires types to have Default +
new_from_template, only requiring Clone. The
zero constructor uses an internal
Zeroable trait only set for primitive types and their arrays. In the future this concept may be
unsafely extended outside of this crate but for now it's private. As long as this type fits on the stack and
the array fits in memory this should be allocatable.