title: How to get the memory address of a file
body: <p>In a WCE app I’m looking for a way to copy a file (I only have to file name/path of it) to a specific memory address.
  The file is rather large’ish, ~40MB, so with limited resources, I was hoping to avoid reading the whole file into memory (byte array), by using the answer from this post:
  <a href="https://stackoverflow.com/questions/15975972/copy-data-from-from-intptr-to-intptr">Copy data from from IntPtr to IntPtr</a></p>
  
  <pre><code>[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)] 
  public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count); 
  static void Main() 
  { 
      const int size = 200; 
      IntPtr memorySource = Marshal.AllocHGlobal(size); 
      IntPtr memoryTarget = Marshal.AllocHGlobal(size);
      CopyMemory(memoryTarget,memorySource,size); 
  }
  </code></pre>
  
  <p>That leaves me to 2 problems. 
  First of all: <strong>How do I assign a memory address to an IntPtr?</strong>, kind of like: <code>int* startAddr = &amp;0x00180000</code>.</p>
  
  <p>And secondly: <strong>How do I obtain the memory address of a file?</strong></p>
  
  <p>With these two questions answered, my code would look something like:</p>
  
  <pre><code>[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
  public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
  private unsafe void CopyFile()
  {
      try
      {
          fixed (Int32* startAddr = /*0x00180000*/)
          {
              fixed(Int32* fileAddr = /*Memory Address of file*/)
              {
                  CopyMemory(new IntPtr(startAddr), new IntPtr(fileAddr), (uint)new FileInfo("File name").Length);
              }
          }
      }
      catch { }
  }
  </code></pre>
  
  <p>Would that be a valid way of going about it?</p>
  
  <p>Any help would be greatly appreciated. Thanks in advance!!</p>
  
  <p><strong>Update:</strong>
  CopyMemory is not the way of going about it. So please disregard.</p>
  
  <p>Also, Sorry for not being clearer. Basically I want to move a file to the start of a partition on disk. I thought that IntPtr could also point to a disk address, but in retrospect I can see that of course it can not. 
  Anyway sorry for the confusion.</p>