In C it can be better to pass pointers to larger structs.
Example of return-by-value:
typedef struct LargeStruct {
char data[512];
} LargeStruct;
/* snip */
void some_function() {
for (int i = 0; i < total; ++i) {
LargeStruct value = some_other_function();
/* use 'value' */
}
}
In this case its often preferable to pass a pointer to the struct. eg:
for (int i = 0; i < total; ++i) {
LargeStruct value;
some_other_function(&value);
/* use 'value' */
}
... so each function call doesn't have to make a copy of the struct.
My question is: Does this apply to Rust too?
Are return values handled differently to C that make it unnecessary to pass return-arguments?