Jump to content
  • Advertisement
Sign in to follow this  
ReKlipz

iostream(or fstream) vs FILE *

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!