title: Possible GDI+ DrawLines Optimization pondering
body: <p>I am trying to get more performance out of c# GDI+ DrawLines function. When I run a profiler on the the code I see that almost half of the time spend in the DrawLines function is preparing the point array to be send over to the native GDI+ dll. This seems like a big overhead and I am wondering if anyone could come up with a more efficient way interop-ing with the DrawLines function than the native implementation of the DrawLines function in System.Drawing</p>
  
  <p>Here are the native Systemm.Drawing functions: </p>
  
  <pre><code>public void DrawLines(Pen pen, PointF[] points)
  {
      if (pen == null)
      {
          throw new ArgumentNullException("pen");
      }
      if (points == null)
      {
          throw new ArgumentNullException("points");
      }
      IntPtr handle = SafeNativeMethods.Gdip.ConvertPointToMemory(points);
      int status = SafeNativeMethods.Gdip.GdipDrawLines(new HandleRef(this,this.NativeGraphics), new HandleRef(pen, pen.NativePen), new   HandleRef(this, handle),     points.Length);
  Marshal.FreeHGlobal(handle);
      this.CheckErrorStatus(status);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>internal static IntPtr ConvertPointToMemory(PointF[] points)
  {
      if (points == null)
      {
          throw new ArgumentNullException("points");
      }
      int num2 = Marshal.SizeOf(new GPPOINTF().GetType());
      int length = points.Length;
      IntPtr ptr = Marshal.AllocHGlobal((int) (length * num2));
      for (int i = 0; i &lt; length; i++)
      {
          Marshal.StructureToPtr(new GPPOINTF(points[i]), (IntPtr) (((long) ptr) + (i * num2)), false);
      }
      return ptr;
  }
  </code></pre>