spectral

Which is the best ?

Discussion created by spectral on Sep 8, 2010
Latest reply on Oct 1, 2010 by himanshu.gautam

Hi,

I have 2 ways to create a method to get back a result... but which one is the best, in term of memory and performance ?

MyData t;
myFunction(&t);

void myFunction(MyData* data) { .... data.val = 10; ... }

or

MyData t = myFunction();

MyData myFunction() { MyData data; data.val = 10; return data; }

By example, in the first version, I think that we avoid the creation of 2 MyData, but it really depend of the compiler optimization.

Outcomes