title: Is there any downside to using unmanaged structs by ref?
body: <p>In many api samples we get IntPtr as a pointer to structure, and I see that people allocate new memory, copy all data, and then create a new structure as I understand it. Or they use Marshal.PtrToStructure (). What is the difference in using Marshal.PtrToStructure() and just ref Struct? In case I just need to read some structure data.</p>
  
  <pre><code>[DllImport("some.dll")]
  static extern IntPtr GetPoint(IntPtr point);
  
  delegate IntPtr GetPointDelegate(IntPtr point);
  
  // assing function that will be invoked
  GetPointDelegate callback = ConsumePoint;
  
  // delegate implementation
  IntPtr ConsumePoint(IntPtr ptr)
  {
      Point point = (Point)Marshal.PtrToStructure(ptr, typeof(Point));
      // do stuff with point
      return IntPtr.Zero;
  }
  </code></pre>
  
  <pre><code>[DllImport("some.dll")]
  static extern IntPtr GetPoint(ref Point point);
  
  delegate IntPtr GetPointDelegate(ref Point point);
  
  GetPointDelegate callback = ConsumePoint;
  
  IntPtr ConsumePoint(ref Point point)
  {
      // do stuff with point
      return IntPtr.Zero;
  }
  </code></pre>
  
  <p>How is this different?
  Is this translated to the same thing? Or is it more efficient in the second way but there are some dangers when using it?</p>