Suppose I have two functions
void ProcessData(HugeDataStructure &data) { DoSomething(data); }
void ProcessDataInefficiently(HugeDataStructure data) { DoSomething(data); }
In my code, I have a pointer to the data
HugeDataStructure *p = &SomeValidDataStructure;
When I invoke the function
ProcessDataInefficiently(*p);
I believe I am making a huge copy (of the data structure) onto the stack. On the other hand, when I invoke the function
ProcessData(*p);
am I still making a copy of the data onto the stack? In other words, is "*p" inducing a copy? Compare this case to the following case
*p = AnotherValidDataStructure;
Here, I am copying the contents of AnotherValidDataStructure into SomeValidDataStructure, so a copy is, in fact, performed. Does this hold when passing a dereferenced pointer where a reference is required? I'm pretty sure it does not, but can't find documentation to the effect.
Please, let's not get into a "when you should use pointers and when you should use references" discussion. I did not write the methods that I need to invoke, so it's out of my hands. I want to ensure I'm not making huge copies onto the stack when I invoke
ProcessData(*p);
vs
ProcessDataInefficiently(*p);
Thanks