I was reviewing some code, and they basically had:
while (true) // update loop
{
someStruct = new SomeStruct(1,2);
}
Creating objects like that in a loop is bad, you should create it once and then update it to avoid creating/destroying millions of them.
But this isn't a problem:
while (true) // update loop
{
x = x + 1;
}
Since x is a value type. But then structs are also kind of similar to value types. They are apparently not subject to garbage collection.
So now I'm wondering if there's any performance cost with creating structs in a loop or if you should still create one and update it (code readability/future proofing aside).