use std::rc::Rc;
pub fn test() -> Rc<[usize; 1024]> {
Rc::new([42; 1024])
}
If I compile this code, I can see that Rust fills up an array with 42 on the stack, then allocates on the heap and invokes memcpy to copy over the values from the stack to the newly allocated area which is wasteful.
What's the easiest way to ask Rust to initialize the array directly on the heap without initializing it on the stack first to avoid the memcpy?