I have a type that takes up too much stack space:
struct Foo {
lots_of_bytes: [u8; 1024 * 10],
bar: bool,
baz: isize,
}
There are two obvious solutions:
let foo = Box::new(Foo::new());
Or
struct Foo {
lots_of_bytes: Box<[u8; 1024 * 10]>,
bar: bool,
baz: isize,
}
To summarize, I either select the entire structure on the heap, or I may have my own heap pointer. Is any of these solutions an “idiomatic” solution? Or is it strictly subjective or contextual?
source
share