> On 2010-12-22 22:05-0700 Maurice LeBrun wrote:
>> A cautionary note: PL_MAXPOLY impacts a fair amount of code. Also there
>> are
>> heap-vs-stack performance implications -- e.g. directly moving from a
>> fixed
>> allocation to a malloc/free each time plfill() is called could suck for
>> the
>> many small-n-vertices polygon case. Using per-stream polyline buffers is
>> better but more convoluted. The short term solution is definitely just
>> recompile with a higher limit.
Attached I send a patch for svn plfill() that uses malloc/free in case
of n > PL_MAXPOLY-1. I've used a behavior similar to the function
plP_plfclp() in plfill.c. plP_plfclp tests if the number of point is
greater than PL_MAXPOLY and uses static or dynamic array in
consequence. I've done the same for c_plfill() and c_plfill3(), so for
polygons with small number of vertices no overload is done for the
using of malloc/free. This only introduces two if's sentences: for
test if malloc must be used and for tests if free must be used. And
deletes a if sentence: the check if ( n < PL_MAXPOLY ) in the test for
determining if the last point is the same as the initial in tle
polyline defining the polygon.
Can anyone check the patch?
Thanks
--
*****************************************
José Luis García Pallero
jgpall...@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************
Index: trunk/src/plfill.c
===================================================================
--- trunk/src/plfill.c (revisión: 11383)
+++ trunk/src/plfill.c (copia de trabajo)
@@ -5,6 +5,9 @@
// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Alan W. Irwin
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Arjen Markus
//
+// 2010-12-23, José Luis García Pallero, change static vectors of length
+// PL_MAXPOLY to dynamic (malloc, free)
+//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
@@ -130,7 +133,8 @@
void
c_plfill( PLINT n, PLFLT *x, PLFLT *y )
{
- PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
+ PLINT _xpoly[PL_MAXPOLY], _ypoly[PL_MAXPOLY];
+ PLINT *xpoly, *ypoly;
PLINT i;
PLFLT xt, yt;
@@ -144,11 +148,30 @@
plabort( "plfill: Not enough points in object" );
return;
}
+// if ( n > PL_MAXPOLY - 1 )
+// {
+// plwarn( "plfill: too many points in polygon" );
+// n = PL_MAXPOLY;
+// }
if ( n > PL_MAXPOLY - 1 )
{
- plwarn( "plfill: too many points in polygon" );
- n = PL_MAXPOLY;
+ xpoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) );
+ ypoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) );
+
+ if (( xpoly == NULL ) || ( ypoly == NULL ))
+ {
+ free(xpoly);
+ free(ypoly);
+ plabort( "plfill: Insufficient memory" );
+ return;
+ }
}
+ else
+ {
+ xpoly = _xpoly;
+ ypoly = _ypoly;
+ }
+
for ( i = 0; i < n; i++ )
{
TRANSFORM( x[i], y[i], &xt, &yt );
@@ -158,7 +181,7 @@
if ( x[0] != x[n - 1] || y[0] != y[n - 1] )
{
- if ( n < PL_MAXPOLY )
+// if ( n < PL_MAXPOLY )
n++;
TRANSFORM( x[0], y[0], &xt, &yt );
xpoly[n - 1] = plP_wcpcx( xt );
@@ -167,6 +190,12 @@
plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
plsc->clpymi, plsc->clpyma, plP_fill );
+
+ if ( n > PL_MAXPOLY - 1 )
+ {
+ free(xpoly);
+ free(ypoly);
+ }
}
//--------------------------------------------------------------------------
@@ -181,9 +210,11 @@
void
c_plfill3( PLINT n, PLFLT *x, PLFLT *y, PLFLT *z )
{
- PLFLT tx[PL_MAXPOLY], ty[PL_MAXPOLY], tz[PL_MAXPOLY];
+ PLFLT _tx[PL_MAXPOLY], _ty[PL_MAXPOLY], _tz[PL_MAXPOLY];
+ PLFLT *tx, *ty, *tz;
PLFLT *V[3];
- PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
+ PLINT _xpoly[PL_MAXPOLY], _ypoly[PL_MAXPOLY];
+ PLINT *xpoly, *ypoly;
PLINT i;
PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale;
@@ -197,11 +228,39 @@
plabort( "plfill3: Not enough points in object" );
return;
}
+// if ( n > PL_MAXPOLY - 1 )
+// {
+// plwarn( "plfill3: too many points in polygon" );
+// n = PL_MAXPOLY;
+// }
if ( n > PL_MAXPOLY - 1 )
{
- plwarn( "plfill3: too many points in polygon" );
- n = PL_MAXPOLY;
+ tx = (PLFLT *) malloc( ( n + 1 ) * sizeof( PLFLT ) );
+ ty = (PLFLT *) malloc( ( n + 1 ) * sizeof( PLFLT ) );
+ ty = (PLFLT *) malloc( ( n + 1 ) * sizeof( PLFLT ) );
+ xpoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) );
+ ypoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) );
+
+ if (( tx == NULL ) || ( ty == NULL ) || ( tz == NULL ) ||
+ ( xpoly == NULL ) || ( ypoly == NULL ))
+ {
+ free(tx);
+ free(ty);
+ free(tz);
+ free(xpoly);
+ free(ypoly);
+ plabort( "plfill: Insufficient memory" );
+ return;
+ }
}
+ else
+ {
+ tx = _tx;
+ ty = _ty;
+ tz = _tz;
+ xpoly = _xpoly;
+ ypoly = _ypoly;
+ }
plP_gdom( &xmin, &xmax, &ymin, &ymax );
plP_grange( &zscale, &zmin, &zmax );
@@ -213,7 +272,7 @@
}
if ( tx[0] != tx[n - 1] || ty[0] != ty[n - 1] || tz[0] != tz[n - 1] )
{
- if ( n < PL_MAXPOLY )
+// if ( n < PL_MAXPOLY )
n++;
tx[n - 1] = tx[0]; ty[n - 1] = ty[0]; tz[n - 1] = tz[0];
}
@@ -244,6 +303,15 @@
//
plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
plsc->clpymi, plsc->clpyma, plP_fill );
+
+ if ( n > PL_MAXPOLY - 1 )
+ {
+ free(tx);
+ free(ty);
+ free(tz);
+ free(xpoly);
+ free(ypoly);
+ }
}
//--------------------------------------------------------------------------
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel