Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, I would not use unsafe code for this unless I had first determined (1) that the obvious code with the switch would be <strong>the slowest code in the entire program</strong> and causing significant, user-observable slowdowns, and that (2) going to unsafe code fixes the performance problem.</p> <p>Second, if I were to use unsafe code, it is extraordinarily dangerous to make assumptions about structure packing. The CLR is allowed broad lattitude in how it chooses to pack structures. <strong>If you are going to do this dangerous thing then you should use the struct layout attribute to ensure that the floats are exactly where you need them to be.</strong></p> <p>Third, what stops a buggy caller from passing a negative index, or a too-large index?</p> <p>Fourth:</p> <blockquote> <p>Does fixed create redundant overhead here? </p> </blockquote> <p>I don't know what "redundant overhead" means. "fixed" makes the jitter tell the garbage collector "do not move this thing because I need to do pointer arithmetic on it". You are fixing for a short period, which is ideal; fixing for a long time makes it more likely that a collection will get messed up because the pinned storage could not be moved.</p> <p>Fifth:</p> <blockquote> <p>Or maybe this struct is already fixed, and therefore fixed has no effect here and is only needed to satisfy the compiler?</p> </blockquote> <p>Maybe! Maybe the variable referred to by "this" is already a fixed variable. <strong>Maybe it isn't.</strong> How is the <em>compiler</em> supposed to know whether the "this" of the struct is a ref to fixed storage or not? We have to assume the worst, so you are required to fix it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload