> < ^ Date: Tue, 04 Jul 1995 08:58:00 +0100
> < ^ From: Steve Linton <sal@dcs.st-and.ac.uk >
< ^ Subject: Re: Memory concerns.

Dear Forum,

Bruce Merz reported memory problems. The main symptom of which was
erratically slow performance. I sent a reply to him a few days ago,
and since no one else has replied to the forum I'm repeating it here
(without the typing mistakes, hopefully).

The first thing to do with this sort of problem is to find out how
many garbage collections are occurring by running GAP with the -g
option. This will cause the garbage collector to print a message
each time it reclaims space.

If it is not managing to reclaim very much space each time then it
will do very frequent collections and your calculation will run very
slowly. The only real fix for this is to either: (a) find a way to
do your calculation with less memory use (b) find a computer with
more memory.

If it is reclaiming a lot of space, but refilling it very quickly
each time, then you need to refine your GAP code allocate less
space. Essentially the secret is to alter lists in-place (using
list[i] := ...) rather than to create new lists. Of course this is
not always possible, and you need to keep rather careful track of
who has a pointer to the list you are altering, but that is the
price for higher performance. Other tips include using ShallowCopy
instead of Copy, when you can, and the l{} construction instead of
Sublist. In fact, if you are not planning to change the data, you
can often avoid Sublist commands by simply atoring the ranges of
indices.

A third possibility is that are using virtual memory, in which case
your computer is working hard to swap data between memory and disk.
In this case it might be better to give GAP a slightly _smaller_
workspace, accept the more frequent garbage collections and avoid
the disk activity. Try running with (say) 12, 13, 14 and 15 MB of
memory and see what happens in each case.

If you continue to have problems try sending your code in to
gap-trouble and we will see what we can see.

Good luck
        Steve

> < [top]