Passing parameters

Which is faster? passing parameters to function by reference or by itself (owner moving context)

Ther's no single answer. It depends on the size of the argument passed.


Does the location of data in memory changed in owner moving?

Theoretically yes, but it can often be optimized away.

"move" in Rust does not imply that any data is actually, physically, moved around in memory. "move" is a high level, conceptual, idea at compile time about who owns data. The owner is the one responsible for the destruction (deallocate, free) of the data when it is no long in use.

You might be interested in this recent discussion about "move": Why do values need to be moved? - #3 by alice


Heap allocations aren't moved, but the stack portion may need to be physically moved. As I said, it may be optimized away.


Quite so.

A function may well be compile to inline code. At which point nothing need be physically moved I presume.

Optimisers move in mysterious ways, their wonders to perform.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.