First, I would not use unsafe code for this if I had not determined (1) that the obvious code with the switch would be the slowest code in the whole program and would cause significant, user-serviced slowdowns and that (2) the transition to unsafe The code fixes a performance issue.
Secondly, if I use unsafe code, it is extremely difficult to make assumptions about packing the structure. The CLR allows for widespread relaxation in how it decides to pack structures. If you are going to do this dangerous thing, then you should use the structure structure attribute to ensure that the floats are exactly where you need to.
Thirdly, what causes the buggy caller to transmit a negative index or an index too large?
Fourth:
Is fixed creation of excess overhead here?
I do not know what "excess overhead" means. "fixed" causes jitter to tell the garbage collector to "don't move this thing because I need to do pointer arithmetic on it." You are corrected for a short period, which is ideal; committing for a long time makes it more likely that the collection will be mixed up because the pinned vault cannot be moved.
Fifth:
Or maybe this structure has already been fixed, so fixing it has no effect here and is only required to satisfy the compiler?
May be! Perhaps the variable referenced by "this" is already a fixed variable. Perhaps this is not so. . How should the compiler know if the "this" structure is a reference to fixed storage or not? We have to accept the worst, so you need to fix it.
source share