The Rust Box::new(X) method first creates X on the stack, then allocates memory
and copies X from the stack to the heap. That is very wasteful if X is large.
- Github issue: rust-lang/rust#49733
- Workaround crate: https://github.com/kvark/copyless
Now, it turns out that there is a compiler intrinsic that you can use to allocate a Box and initialize it right on the heap. It's not directly exposed via the standard library, but it is used by the vec! macro here.
So you can use vec! to initialize structures right on the stack. But what if you wanted a Box and not a Vec? Use this macro: