iostream(or fstream) vs FILE *

Started by
3 comments, last by Arild Fines 18 years, 8 months ago
I am currently using fstream to input data for MD5 files in my engine, and recently saw a tut that used FILE * for input, and thought to myself... "Is this a faster way to load data than fstreams?", and seeing as how i had no clue, i decided to make this post and get some info from people who DO know(isnt that the whole point of a forum? share ideaz and knowledge?!) so ya, any comments are welcomed, just make sure u can back up which is faster with evidence maybe... I am gonna quick write a proggie that uses both and just writes like a 200MB file, and which ever finishes in the shortest time winz... i guess(this is also measuring HDD speed, but since its the same pute, dont matter) i realize that FILE is realy only on windowz. but thats all my game will be for in the start, so it works...
Advertisement
The issue is really not speed - I doubt one will be faster than the other at all.

FILE* along with fread, fwrite etc. are the C-style way of dealing with files.
fstream along with its read, write etc. methods are the C++ style.

Use whichever you feel more comfortable with; it won't matter.

Oh and FILE* works on all OS's not just Windows - it is part of the c standard library.
The FILE * routines are part of the C runtime library, so is cross platfrom, not just Windows. For large amounts of data, FILE * and fstream run at about the same speed since the limiting factor becomes the hard disk I/O speed and not the file I/O interface you use. For smaller amounts of data FILE * operations tend to be faster, however, you sacrifice type safety and, to a degree, program correctness to get that speed.
Quote:Original post by Simian Man
The issue is really not speed - I doubt one will be faster than the other at all.


On the contrary, there is quite a speed difference between the various file handling methods (on Win32 at least). I did some speed tests for a project i'm working on at the minute and the Win32 CreateFile, ReadFile etc. were fastest, with fstream (ifstream IIRC) being the slowest.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Quote:Original post by JY
I did some speed tests for a project i'm working on at the minute and the Win32 CreateFile, ReadFile etc. were fastest, with fstream (ifstream IIRC) being the slowest.

Which makes sense, given that, implementation wise, one is stacked upon the other.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement