Does or does not allocate temporary variables?

Can someone explain the difference between Input.touches[0] and Input.GetTouch(0) a little clearer for me?

When the docs say “does not allocate temporary variables” what the devil are they referring to? pass by reference verses object copy?

Any special use case(s) where I’d want one over the other?

Thanks,

Galen

temporary variables are variables like

var temp = GetComponent(...);
return temp;

and similar which need to be garbage collected.
There are cases where it can’t be avoided but if you only need the return of something once, do not store it into a variable but use it directly, that will save you garbage collection and memory allocation, two of the more impacting things performance wise

ok, perphaps I worded my question incorrectly… :slight_smile:

I understand temporary allocation, GC, alloc, and compaction… but… what are the docs referring to around touches?

If I intrepret what is written in the docs, then the array allocates a temp variable on index request, and the GetTouch does not?

How is that possible?

And while there are performance implication for me by using one method over another, doesn’t Get use the touches array internally anyway??

Or does touches implement a custom list (array or variant) class that encapsulates the actual touches array, allocs a temp varialble on index request, while the Get method returns a reference to the actual array element object directly?

Just trying to understand,

Cheers,

Galen