Quote:Original post by TheveninQuote:Original post by ender7771
When you declare x and then pass it as an argument, you are only passing the value, not the location. It doesn't matter where it was declared.
Yuppers, but is there a performance hit for putting it in the for loop.
I know that the C# compiler will optimize just about everything you write, but that doesn't always produce an acceptable solution; this part of the code is in the heart of my graphics procedures so I'm not even worried about "premature optimization".
Java (and I would assume C#/.NET) uses a generational garbage collector that is heavily optimized for very short-lived objects, those being the most common.
So while I would say that if it's simple to reuse the object, I would, but I wouldn't be too concerned about it unless you really were trying to squeeze the last bit of performance out of the loop - in which case you can find out by trying both and see which is faster, which will give you a conclusive answer.