slowness part2

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

This is a simplified demo of the problem I posted this morning... boiled
down to just the basic case that is causing my app to run painfully slow.
Seems like the slow part is using the graphicsPath Point accessor. Can
anyone see how I could speed this up?

//main test form button handler
private void button1_Click(object sender, System.EventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath gp = new
System.Drawing.Drawing2D.GraphicsPath();
for( int i = 0; i < 2000; i++ )
{
gp.AddLine( i,i, i+2, i );
}

ArrayList list = new ArrayList();
PointF pointF = new PointF( 0,0 );
for ( int i = 0; i < gp.PointCount; i++ )
{
list.Add( gp.PathPoints );

//test.. this is about the speed I would expect
//Point2D p = new Point2D( i,i );
//list.Add( p );
}

int j = 0;//just line so I can put a break point here
}

//---------------------differnt class
class Point2D
{
float m_X, m_Y;

public Point2D( float x, float y )
{
m_X = x;
m_Y = y;
}

public Point2D( PointF p )
{
m_X = p.X;
m_Y = p.Y;
}
}
 
nm, somone pointed out to me I can clone the pointList so I dont have to go
through the nasty Points accessor.. it IS much faster now.

PointF []point = (PointF[])gp.PathPoints.Clone();
 
Hi Jason,

Well I'm just guessing, but have you considered the possibility that the
PathPoints property is constructed from scratch *each* time around the loop.
What about just trying list.AddRange(gp.PathPoints)

Cheers

Doug Forster
 
Back
Top