Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!shelby!agate!usenet.ins.cwru.edu!gatech!uflorida!reef.cis.ufl.edu!jdb From: jdb@reef.cis.ufl.edu (Brian K. W. Hook) Newsgroups: comp.os.msdos.programmer Subject: Re: Fastest dump to disk? Message-ID: <26994@uflorida.cis.ufl.EDU> Date: 18 Feb 91 13:56:08 GMT References: <91043.105618JJLUCSY@MTUS5.BITNET> <2184@umriscc.isc.umr.edu> <1091@usage.csd.unsw.oz.au> Sender: news@uflorida.cis.ufl.EDU Organization: UF CIS Dept. Lines: 46 In article <1091@usage.csd.unsw.oz.au> pwb@newt.phys.unsw.OZ.AU (Paul W. Brooks) writes: |>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: |> |>Anyone know of any faster way of accessing large amounts of disk data? |>I'd really appreciate hearing it. :-) |>Regards, I have heard somewhere that open(), write(), close(), and read() were not defined in the ANSI standard because of their reliance on handles ( a DOS and UNIX system specific thing). Thus fopen() and the other stream based functions would seem to be a bit more portable. However, speed seems to be the issue here, so I would also look in the TC++ manual under _open() and the other file functions with a leading underscore. I don't know if they are any faster, but they seem to a bit more low level. Inline asm might be also used...:) Brian