You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm passing it to a function by value, and the function does not modify the argument which means it should be equivalent to passing it by reference:
fnprocess(arg:HugeCopyType){let sum = arg.arr.iter().sum::<i64>();println!("{}", sum);}
I'm calling the function from a loop:
let hct = HugeCopyType{arr:[0;1024],};for _ in0..512{process(hct);}
I expected Rust to be smart about this and convert the argument to be passed by reference, however it seems like that is not the case and it ends up being memcpy'd over and over inside the loop (see godbolt link above).
Changing the argument to pass by reference manually gets rid of the memcpys.