Trying to keep my C# code optimized, I found that if I have a list of structure elements, each insertion would be a full copy – something that I would like to avoid.
In C++ I would simply keep a list of pointers and so I was wondering if I can do the same using C#, maybe by having the list as a list of references to the structure.
Unfortunately the structure cannot be turned into a class as it is part of the XNA library (Vector3, Matrix, etc…)
In any case – how would the format and usage look like if it’s possible?
Thanks.
No, basically. Options:
As an example of the last;
Both the .X, and any usage within SomeMethod, are accessing the value directly in the array, not a copy. This is only possible with vectors (arrays), not lists.
One reason a list of refs to structs isn’t possible: it would allow you I store, in the list, the address of a variable on the stack; the array usually outlives the variable on the stack, so that would be ludicrously unsafe