> < ^ Date: Thu, 24 Mar 1994 17:44:00 +0100
> < ^ From: Steve Linton <sal@dcs.st-and.ac.uk >
> < ^ Subject: Re: AppendTo

To be able to call an external executable, it's necessary to write
information to a file. As far as I know, GAP offers the functions
PrintTo and AppendTo. These functions both open a file, write the
information and close it again (am I right?) So when the function
AppendTo is used within a loop, writing in each cycle a small amount
of information, the file is opened and closed again very often,
consuming a huge amount of time.

This is an especially bad problem under DOS, as UNIX gains the
benefit of disk caching.

Is there a way to open a file once, write all the information using
a loop, and close it again?

I don't believe so.
>
> I have thought of using strings. First, all the information is stored
> in a string (using Concatenation), after which the whole string is
> written to a file using PrintTo. It turns out that, at least when
> working under DOS, this is even slower than the first option.
>

Better is to put all the information into a GAP list and then write
it out in one go. If your external program can't handle the
resulting [] and ,s then you may have to write a little filter to
strip them out.

Another trick is to put the file on a RAM disk.

Steve


> < [top]