title: What's the fastest way to ReadProcessMemory?
body: <p>I'm trying to search for all instances of a null-terminated string the memory of a process. I enumed all the alloced memory areas with VirtualQueryEx, then I read them with ReadProcessMemory to a byte array and search using this algo (which I found here and the author claims to be the fastest)</p>
  
  <pre><code>    public static unsafe List&lt;long&gt; IndexesOf(byte[] Haystack, byte[] Needle) {
          List&lt;long&gt; Indexes = new List&lt;long&gt;();
          fixed (byte* H = Haystack) fixed (byte* N = Needle) {
              long i = 0;
              for (byte* hNext = H, hEnd = H + Haystack.LongLength; hNext &lt; hEnd; i++, hNext++) {
                  bool Found = true;
                  for (byte* hInc = hNext, nInc = N, nEnd = N + Needle.LongLength; Found &amp;&amp; nInc &lt; nEnd; Found = *nInc == *hInc, nInc++, hInc++) ;
                  if (Found) Indexes.Add(i);
              }
              return Indexes;
          }
      }
  </code></pre>
  
  <p>It works, but it's too slow. Is there a way to memory map the process or somehow search faster in its memory?</p>