El día 23 de diciembre de 2010 09:55, José Luis García Pallero
<jgpall...@gmail.com> escribió:
>> 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

Hi again,
Attached I send a similar patch (trunk svn plplot) for plgradient.c

-- 
*****************************************
José Luis García Pallero
jgpall...@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************
Index: plgradient.c
===================================================================
--- plgradient.c	(revisión: 11383)
+++ plgradient.c	(copia de trabajo)
@@ -78,7 +78,8 @@
     {
       #define NGRAD    2
         int   i, irot_min, irot_max;
-        PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
+        PLINT _xpoly[PL_MAXPOLY], _ypoly[PL_MAXPOLY];
+        PLINT *xpoly, *ypoly;
         PLINT xgrad[NGRAD], ygrad[NGRAD], clpxmi, clpxma, clpymi, clpyma;
         PLFLT dxgrad[NGRAD], dygrad[NGRAD], xrot, xrot_min, xrot_max;
 
@@ -127,11 +128,31 @@
         plsc->ngradient = NGRAD;
 
 
+//         if ( n > PL_MAXPOLY - 1 )
+//         {
+//             plwarn( "plgradient: too many points in polygon" );
+//             n = PL_MAXPOLY;
+//         }
+
         if ( n > PL_MAXPOLY - 1 )
         {
-            plwarn( "plgradient: 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( "plgradient: Insufficient memory" );
+                return;
+            }
         }
+        else
+        {
+            xpoly = _xpoly;
+            ypoly = _ypoly;
+        }
+
         for ( i = 0; i < n; i++ )
         {
             xpoly[i] = plP_wcpcx( x[i] );
@@ -139,7 +160,7 @@
         }
         if ( x[0] != x[n - 1] || y[0] != y[n - 1] )
         {
-            if ( n < PL_MAXPOLY )
+//             if ( n < PL_MAXPOLY )
                 n++;
             xpoly[n - 1] = plP_wcpcx( x[0] );
             ypoly[n - 1] = plP_wcpcy( y[0] );
@@ -149,6 +170,12 @@
         // Plot line corresponding to gradient to give visual
         // debugging cue.
         plline( NGRAD, dxgrad, dygrad );
+
+        if ( n > PL_MAXPOLY - 1 )
+        {
+            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

Reply via email to