Complex world.
Pass-by-value vs Pass-by-reference
by James Mitchell
From the article:
Let’s dig into the age old question, should you pass-by-value or pass-by-reference in C++? (or by pointer in C)
This blog post is mostly a re-post of a reddit comment that I made on r/cpp about pass-by-value and pass-by-reference, with some minor improvements, to make it easier to reference and save.
The answer isn’t as easy as it might seem, it depends on the Application Binary Interface (ABI) and your use-cases, there isn’t a one size fits all answer, this is even more the case for anything which is built to be cross platform.
First it’s probably good to break the problem down into two parts (focusing solely on performance, ignoring readability and maintainability which should often be more important)
- The language construct costs (copying, moving, etc)
- Compiler implications (aliasing, pointer provenance, etc)
- The ABI (the stack, registers, etc)...
Add a Comment
Comments are closed.