[metapost] ! MetaPost capacity exceeded

Dan Luecking luecking at uark.edu
Mon Feb 9 18:25:51 CET 2009


At 07:17 PM 2/7/2009, you wrote:


>If you change froct(5) in picture 3, then the capacity is exceeded 
>800000 already, which is strange because 8^5 is only 32768,

That's 8^5 path segments. Each path segment requires 4 points (two
endpoints and two control points) and each point is a pair of
numbers, so thats 8 numerical memory locations. As Taco pointed out,
when a path is stored in a picture, additional memory is required
(probably such things as its color, whether filled or stroked,
penwidth, etc.).


>def froct(expr m)=
>  if m=0:
>    fill p0 scaled ((y+u)/u) withcolor red;
>  else:
>   fill p0 withcolor red;
>   h0:=currentpicture;
>   currentpicture:=nullpicture;
>
>these two highlighted sentences look redundant, so I pull them 
>outside of function froct such as:
>
>   fill p0 withcolor red;
>   h0:=currentpicture;
>   currentpicture:=nullpicture;
>
>def froct(expr m)=
>  if m=0:
>    draw h0 scaled ((y+u)/u);
>  else:
>   draw h0;
>
>
>this looks more efficient to me, but in this case, it cannot even 
>perform 4 iterations. So, obviously, it is less efficient than the 
>original one.

The "draw" command puts a copy of h0 onto currentpicture. At that
point you have two copies of the picture (one in h0 and one in
currentpicture. Your rearrangement may (or may not) be more
time-efficient, but it is no more memory efficient. It may be worse
(depending on other code changes).

>
>I am just a beginner of programming (this is basically my first), I 
>would appreciate it very much if any experts can give some insight.

Pictures are pretty memory-intensive. Having several defined at
one time makes things worse. One way to keep memory under control
is to use as few as possible. For example, if possible, just add
things to currentpicture as you create them and stop copying
currentpicture to another picture. If that is not feasible, keep
currentpicture completely out of the process. Change the fill and
draw commands to commands that add directly to h0 (for example:
Since draw is defined (for a path P) as
   addto currentpicture doublepath P;
you could do
   addto h0 doublepath P;
and skip currentpicture entirely. Also
   addto h0 contour P;
will add a filled contour P to picture h0.


Dan


Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
"Dubito ergo cogito, cogito ergo sum" --Descartes



More information about the metapost mailing list