title: Initialize a collection of byte* in C#
body: <p>My unsafe method accepts a collection <code>byte[]</code>s. All of these <code>byte[]</code>s are of the same size.</p>
  
  <p>I need to iterate over them all, searching for certain patterns. The search is inherently reinterpret-cast style: at each offset, I need to consider a value as if it were a float, a double, a short, an int, etc. So getting a <code>byte*</code> for each input <code>byte[]</code> and incrementing it on each iteration seems like a natural approach.</p>
  
  <p>Unfortunately I can't find any way to create a collection of <code>byte*</code> - or, more specifically, to initialize it from a collection of arrays. Any ideas?</p>
  
  <p>Here's a somewhat contrived version of the task:</p>
  
  <pre><code>static unsafe void SearchIteration(List&lt;byte[]&gt; arrays, byte[] resultArr)
  {
      fixed (byte* resultFix = resultArr)
      {
          byte* resultPtr = resultFix;
          byte*[] pointers = new byte*[arrays.Count];
  
          &lt;some code to fix all the arrays and store the pointers in "pointers"&gt;
  
          int remaining = resultArr.Length;
          while (remaining &gt; 0)
          {
              &lt;look at resultPtr and each of the pointers and update *resultPtr&gt;
  
              remaining--;
              for (int i = 0; i &lt; pointers.Length; i++)
                  pointers[i]++;
          }
      }
  }
  </code></pre>
  
  <p>Essentially the question is how to initialize <code>pointers</code> with the addresses of <code>arrays</code>, while pinning the arrays so that GC doesn't move them.</p>