Re: [S] Memory problems: solution

Chuck Taylor (chuck@statsci.com)
Wed, 25 Feb 1998 08:12:45 -0800 (PST)


For the record, the change recommended below to speed up loops in S-PLUS
has been incorporated into the language begining with S-PLUS 4.0. Quoting
from the Release Notes, "for(), while(), and repeat() loops now have no
useful return value. They used to return the value of the last expression
executed in the loop. This change was made to reduce memory usage in
loops."

Chuck Taylor
Senior Quality Assurance Engineer
MathSoft Inc.
Seattle, WA, USA

On Wed, 25 Feb 1998, Matthew Wiener wrote:

> The following came from Steve Sain, and works like a charm. The growth in
> memory demands from Splus completely stops.
>
> Charles Berry and Don Sun suggested saving the large matrix to a file, and
> calling a C program to calculate the gradient. The C program would read
> the large matrix from a disk, and memory could be managed explicitly in C.
> I never tried this, since modifying nlminb (as below) worked so well.
>
> ---------- Forwarded message ----------
> Date: Tue, 24 Feb 1998 14:02:48 -0600
> From: Steve Sain <ssain@post.cis.smu.edu>
> To: Matthew Wiener <mcw@ln.nimh.nih.gov>
> Subject: Re: [S] Memory problems (update)
>
> Matt,
>
> I'm not sure that this will do the trick, but one thing that I've done is
> modified nlminb a bit. The problem that I found (or was told by some S-Plus
> person at a conference) is that there are numerous while loops inside nlminb
> and that these while statements are subject to the rather infamous problem with
> S-Plus not doing a good job of garbage collecting (or removing) on exiting the
> loops. What I've done is gone through the code and added "NULL" to the end of
> every while loop. For example:
>
> # Original code
> while(temp$iv[1] < 3) temp <- nlminb.0(temp, p, liv, lv,
> objective, bounds, scale)
>
> # New code
> while(temp$iv[1] < 3) {
> temp <- nlminb.0(temp, p, liv, lv,
> objective, bounds, scale)
> NULL
> }
>
> This has the effect of returning the null value on exiting the loop instead of
> everything else that the while loop normally returns. To be honest, I just made
> wholesale changes like this to every while loop. I never went back to see which
> ones were causing my problems. In any event, I don't really understand what is
> going on with the loops and the memory problems. But I've found that I don't
> have problems with nlminb any more.
>
> Steve Sain
>
> --
> Stephan R. Sain
> Department of Statistical Science
> Southern Methodist University
> Dallas, TX 75275-0332
> (214) 768-2459
> ssain@mail.smu.edu

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news