Re: What is the fastest way to do Data File I/O in C++
On Aug 7, 11:16 am, Ian Collins <ian-n...@hotmail.com> wrote:
James Kanze wrote:
On Aug 7, 5:57 am, Ian Collins <ian-n...@hotmail.com> wrote:
HumbleWorker wrote:
Use ofstream class.
That's probably bad advice!
The good advice is to ask on a windows group for the appropriate
platform specific API.
It depends. A good implementation of ofstream is likely to
handle buffering in some clever fashion which would require a
lot of work on your part to duplicate.
I'd expect a memory mapped file (where supported) to be the
fastest and simplest solution, but obviously some testing
would be required.
It depends. For random access, memory mapped files almost
always beat anything else. For sequential access, I've seen
intelligent buffering win out (although more often for reading
than for writing).
Given the quantity of data, of course, and the fact that he's
probably on a PC, IO bandwidth will probably be the limiting
factor, whatever solution he adopts, so he might as well do
whatever is simplest.
True, although the filesystem cache might mask this.
Given the size of his data, I'm not sure.
Again, testing and measuring beats speculation.
I certainly agree with that. I was just throwing out some
ideas. If the original is not fast enough, and the profiler
shows that the problem isn't CPU per se, then he'll have to
experiment with different versions. I just have a sneaky
suspicion, however, that if filebuf is well implemented, and
he's not an expert on the system, he won't be able to beat it.
Of course, if the problem is CPU, because e.g. the standard
requires filebuf to consider locale specific mappings, even if
the file type is binary, or to maintain a local buffer (where as
he has all of his data already formatted and buffered) then it
shouldn't be too hard to come up with something which requires
very little CPU.
As to which case he's in, of course: only his profiler knows for
sure.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34