title: memcpy leads to EXC_BAD_ACCESS
body: <p>I'm converting someone else's C++ to (Objective) C, but I'm having a problem with <code>memcpy</code>. I use it as follows:</p>
  
  <pre><code>memcpy((void *)virtualFlash[virtualFlashAddress], data, dataLength);
  </code></pre>
  
  <p>The variables are defined as follows:</p>
  
  <pre><code>unsigned char virtualFlash[5 * 1024 * 1024]; // 5MB
  NSUInteger virtualFlashAddress; // set to 8 later on
  unsigned char *data = (unsigned char *)[recordData bytes]; // recordData is an NSData object
  NSUInteger dataLength = [recordData length]; // same NSData object
  </code></pre>
  
  <p>I get an EXC_BAD_ACCESS on the line of the memcpy. I debugged <code>recordData</code>, which returned <code>&lt;d8ffbd27 2000b1af 1c00b0af 2400bfaf&gt;</code>, and dataLength, which returned 16--both correct.</p>
  
  <p><code>memcpy((void*)virtualFlash[8], data, 16);</code></p>
  
  <p>This crashes. I've read that <code>memmove</code> works sometimes, but not in my case (same EXC_BAD_ACCESS). I'm unsure what to do, as this is almost exactly copied from the C++ program in which it works fine. My knowledge of C is very minimal, so I may be missing something obvious.</p>