Harald Tveit Alvestrand wrote:
> At 21:37 20.10.99 +0100, Brian J. Beesley wrote:
>
> >But I can write an entire array of any
> >size with one call from a high-level language, whereas writing it
> >byte by byte takes as many calls as there are bytes in the array.
> >Given that the system call is likely to involve a processor context
> >save & restore and a switch from user to kernel privelege & back
> >again, I rather suspect that the single call method may be more
> >efficient.
>
> Only if you use unbuffered I/O, which is highly unusual, and dead slow.
> On some C libraries, if you do byte-at-a-time output, you'll output a
> thousand bytes before you even get the overhead of doing a routine call -
> and almost always a whole data block (1K or 8K, depending) before you do a
> system call.
You could even do the buffering yourself if you can spare an array of
size n*sizeof(int). In pseudo-ish code:
int *intarray;
intarray = malloc(n * sizeof(int));
for (i = 0; i < n; i++)
intarray[i] = (int)round(realarray[i]);
write(output, intarray, n * sizeof(int));
free(intarray);
Obviously you wouldn't malloc/free the array for each save, but you get
the picture. One drawback is that you have n round() calls per save,
but this probably doesn't add up to much in the grand scheme of things.
Does the Windows and/or Mac C compilers have a unixish stdio library
that has buffered I/O with things like fwrite() and friends? If so,
this all becomes a moot point...
As Harald said:
> Certain problems have been solved by others
Simon.
_________________________________________________________________
Unsubscribe & list info -- http://www.scruz.net/~luke/signup.htm
Mersenne Prime FAQ -- http://www.tasam.com/~lrwiman/FAQ-mers