title: Pinning an updateble struct before passing to unmanaged code?
body: <p>I using some old API and need to pass the a pointer of a struct to unmanaged code that runs asynchronous.</p>
  
  <p>In other words, after i passing the struct pointer to the unmanaged code, the unmanaged code copies the pointer and returns immediately. The unmanaged code can access that struct in background, in another thread. <strong>I have no control over the unmanaged code that runs in another thread nor the thread itself.</strong></p>
  
  <p>The fixed { } statement can't be used for pinning because it not designed for async unmanaged pinning.</p>
  
  <p>GCHandle can pin only references, so the struct must be boxed to use GCHandle. I tried it, and it works. The main problem with it, is that you can't update the struct <strong>from managed code</strong>. To update a struct, first of all we need to unbox it, then update, then box again, but... oops ... box again?!? this means the previous pointer in the memory still point to the old non-up-to-date struct, and the new struct have another pointer, and this means that i need to pass new pointer to the unmanaged code... inapplicable in my case.</p>
  
  <p>How can i pin a struct in the memory without fixed { } statement, and so that i can update it <strong>from managed code</strong> without change it's pointer?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Just thought... is there a way to pin the parent object that contains the struct, and then get the pointer of the <strong>struct</strong> rather than the container object?</p>