MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

memory use

Having posted a question about excessive kernel memory use when writing a
relatively small file to disk, I received very much helpful information
from various people.  Thanks to Mark Evans, Harald Berndt, and Paul Rubin
for their especially detailed remarks.

The most immediately useful method offered, which works admirably well, was
supplied by Rolf Mertig.  His remarks and code are as follows:

"Mathematica has a well-known efficiency problem in reading in and
writing out larger files.

"Of course everybody finding this bug should report to support at,
so that it might get fixed still in some new version.

"In the meantime probably the thing to do is use a simple procedural
Do-loop, in good old Fortran-style:

"PutLargeMatrix[{{x1, x2, ...}, {...}, {y1,y2, ...}}, filename]
writes the matrix {{...}} to a file.
The memory-consumption is much less.";
PutLargeMatrix[{x_List, y__List, z_List}, fil_String] := Block[{},
   OpenWrite[fil]; WriteString[fil,"{\n"]; PutAppend[x, fil];
       PutAppend[{y}[[i]], fil];
        (* comment this line out, evtl.*) WriteString["stdout",i," "];
     , {i,Length[{y}]}
   WriteString[fil,","]; PutAppend[z, fil]; WriteString[fil,"}\n"];
   Close[fil]                                                ];
   End[]; EndPackage[];

(* on a HP720, running Mma 2.2, this examples takes about 5.5 minutes and
returns 3843712 for MaxMemoryUsed[]
(* this puts out a 491 x 1091 matrix *)
 PutLargeMatrix[Table[Mod[x,y],{y,491},{x,1091}], "longtest"]

Rolf's method consumes little memory at all in the course of actually
writing the file.  It does seem to me that some such method should be
incorportated as a standard Mathematica function in future releases.

Russell Towle
Giant Gap Press
P.O. Box 141
Dutch Flat, California 95714
Voice:  (916) 389-2872
e-mail:  rustybel at


  • Next by Date: QUESTION
  • Next by thread: QUESTION