Not a real problem, I'm just looking to satisfy curiosity…
Vector GetVector()
{
return new Vector(0, 5);
}
void Update()
{
DoSomething(GetVector() * 2);
}
Vector GetVector()
{
Vector vec = new Vector(0, 5);
return vec;
}
void Update()
{
Vector vec = GetVector();
Vector twiceVector = vec * 2;
DoSomething(twiceVector);
}
In the first example, value is returned, operator function called, and passed in, all inline. Whereas in the second example, each step stores the value as a local.
Would both examples compile the same? Or are there additional allocations (however small) in the second?
Edit: Sorry don't know why this posted to AI. I mustn't have specified a category.