Article View: comp.os.msdos.programmer
Article #4750Re: Fastest dump to disk?
From: Paul W. Brooks
Date: Mon, 18 Feb 1991 02:33
Date: Mon, 18 Feb 1991 02:33
53 lines
2766 bytes
2766 bytes
In article <2184@umriscc.isc.umr.edu>, mcastle@mcs213f.cs.umr.edu (Mike Castle {Nexus}) writes:
> In article <91043.105618JJLUCSY@MTUS5.BITNET> JJLUCSY@MTUS5.BITNET writes:
> >Could someone please tell me what is the fastest way to dump a chunk of memory
> >to disk using either Turbo C v.2 or Turbo C++. I'm not to particular on the
> >method, but it should be real quick. Thanks in advance.
> >
>
> Try fwrite. The prototype is:
>
> size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
>
> It starts at *ptr and writes n records of size size to file pointed to by
> steam.
Sorry - incorrect. The fastest way is using low-level file access -
write(). Using fwrite() requires the disk library internals to keep up
to date with internal buffers, etc., and is quite slow. In my systems I
usually get at least 3 times the speed when using write() instaed of
fwrite()!
There are a couple of things to watch, though. Preferably the
file handle is obtained through the low-level call to open() or creat(). If you
need to write to a file opened using the stream method (fopen()), and
get to the underlying file handle using fileno(stream), then beware that
the buffers probably will not be correct, and any later streams-based
calls (fwrite(), fread(), fgetc(), etc etc) may fail unpredictably.
There are techniques to bring the low-level and higher-level routines
back in line, e-mail me if you need some hints. In my software I have to
manipulate 500K astronomical images, and use only the low-level file
operations:
( in MSC, with some rigorous bits omitted 8-) )
int file,row,bytesout;
( bits missed here )
file = creat("filename",S_IREAD|S_IWRITE);
if (file==-1)
bomb_out();
bytesout =write(file,bufptr,buflen);
if (bytesout!=buflen)
bomb_out();
( more writes here! )
close(file);
Anyone know of any faster way of accessing large amounts of disk data?
I'd really appreciate hearing it. :-)
Regards,
Paul Brooks |Internet: pwb@newt.phys.unsw.edu.au
Uni. of N.S.W. |If you have trouble sleeping, try lying on the end of
Kensington NSW 2033| your bed. With a little luck you'll drop off.
AUSTRALIA | - Mark Twain.
Technical Details
Message-ID:
<1091@usage.csd.unsw.oz.au>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!uokmax!munnari.oz.au!metro!usage.csd.unsw.oz.au!newt.phys.unsw.OZ.AU!pwbReferences:
<91043.105618JJLUCSY@MTUS5.BITNET> <2184@umriscc.isc.umr.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!uokmax!munnari.oz.au!metro!usage.csd.unsw.oz.au!newt.phys.unsw.OZ.AU!pwb From: pwb@newt.phys.unsw.OZ.AU (Paul W. Brooks) Newsgroups: comp.os.msdos.programmer Subject: Re: Fastest dump to disk? Summary: write(), not fwrite() Message-ID: <1091@usage.csd.unsw.oz.au> Date: 18 Feb 91 02:33:19 GMT References: <91043.105618JJLUCSY@MTUS5.BITNET> <2184@umriscc.isc.umr.edu> Sender: news@usage.csd.unsw.oz.au Lines: 53