[GRASS-dev] graph function input limitations

Glynn Clements glynn at gclements.plus.com
Wed Nov 21 20:38:36 PST 2012


Paulo van Breugel wrote:

> > The limit would depend upon the number of columns in the current
> > region and the amount of memory available.
> 
> OK, but what I find strange is that using 2400 terms uses less then 2.5 
> GB, I would not expect 2500 terms to use more then 12 GB (amount of RAM 
> available) in that case.
> I also tried to run a r.mapcalc with 2600 terms for a map of 15 x 19 
> cells. Also here I got the message: "memory exhausted", which can 
> hardly be related to lack of memory?

Right. Debugging indicates that the error actually comes from the
parser, which by default limits the stack to 10000 items. This can be
overridden by defining the macro YYMAXDEPTH in mapcalc.y.

Given that it fails at just under 5000 arguments (each x,y pair adds 2
arguments), I'm assuming that each extra argument to graph() requires
2 stack levels, so the value should be just over twice the maximum
number of arguments.

With the following change, it has no problems with 5000 arguments:

	--- raster/r.mapcalc/mapcalc.y	(revision 53964)
	+++ raster/r.mapcalc/mapcalc.y	(working copy)
	@@ -12,6 +12,7 @@
	 
	 #define YYDEBUG 1
	 #define YYERROR_VERBOSE 1
	+#define YYMAXDEPTH 100000
	 
	 static int syntax_error_occurred;

To be honest, I'm not sure that it's worth increasing this value in
the standard version. 5000 arguments in a function call is rather
extreme, and probably a hint that alternative approaches should be
considered.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list