Memory question.

OK guys, I have a quick question.
If I pass a 4-byte object into a function, does it take up 8-bytes of memory?
And same question, but if I do so with passing by reference.
No. The object will be copied, and each copy will use 4 bytes, but they will be two objects, not one.
The space cost of passing a reference depends on whether the function is being inlined. If it is, there's no extra space cost. If it isn't, the cost of passing a 'T &' is the same as the cost of passing a 'T *'.
Note, however, that some calling conventions allow the compiler to pass parameters through registers, so in principle there is no memory cost.
Topic archived. No new replies allowed.