Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

omegasyphon

fastest way to read in a file

This topic is 6250 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

Advertisement
don''t know for shure... but I''d say they''re about the same... if there is a diffrence then it would be a very small one... small enough not to matter... disk io is exreamly slow so the few clock ticks picked up by using one or the other is going to be so minamal that it isn''t going to matter which you use...

Share this post


Link to post
Share on other sites
The biggest speed increase comes from using binary files.

Ben
http://therabbithole.redback.inifcad.com

Share this post


Link to post
Share on other sites
Opening and closing the same file repeatedly fopen/fclose was able to do 4,399 per second and ifstream::open/ifstream::close could to 4,342 so if you open around 335,000 files fopen will save you ONE second. So, how many are you opening?

Always one for performance trivia I just has to try the Windows API CreateFile. It did 7,564 per second. So you would only have to open 10,500 files to save a second with it.

Edited by - LilBudyWizer on June 5, 2001 3:26:08 PM

Share this post


Link to post
Share on other sites
I supose he asks about wich way of reading files, C-like of C++ streams is fastest. Normally you don´t open many files at runtime.

If you want to write fast to a file, you have to batch as much data as you can instead of writing many small pieces...

What the hells!

Share this post


Link to post
Share on other sites
Both the stdio functions and the c++ streams eventually end up calling CreateFile. So I''d say using that should always be faster than the two alternatives.

Share this post


Link to post
Share on other sites
Sorry, I shouldn't have taken that so literally. I thought you were asking about the open itself so I was demonstrating that it isn't the open you have to worry about, but also how to answer questions like that. I compared a fread to an ifstream.read. Surprisingly there was a pretty dramatic differance. I wrote a 4mb file then used both to read it back. The initial read with fopen read about 2.8mb/s, but once the file was in the file cache it reread the file at 100 to 130mb/s. The ifstream got about 2.3mb/s. It didn't matter if the file was in cache or not. I don't generally use ifstream so I may have made a mistake, but what I was using was:

  
ifstream ifs;
ifs.open("File1.txt", ios::in | ios::binary);
ifs.seekg(0);
for (int i = 0; i < 4096; i++)
ifs.read(ucBuffer, 1024);
ifs.close();


Edited by - LilBudyWizer on June 5, 2001 8:35:24 PM

Share this post


Link to post
Share on other sites
Remember that the processor is faster than your disk. So, although Win32 API calls will be marginally faster than C stdio calls, which in turn will be marginally faster than C++ iostream calls, 99% of the time, the processor will be waiting on the data. So choose whatever method you''re most comfortable with, use optimal algorithms, and I''m sure you won''t notice the difference.

Share this post


Link to post
Share on other sites
Please note that if you use fstreams, and Visual C++ 6 with the C++ library that comes with it, you''re likely to run into a very annoying bug: if you create a fstream (i- or o-) by name, it will be unbuffered, leading to a huge performance hit.

For fixes, see this page. Another option is to use a different STL/IOstreams implementation altogether, and STLport is a good (and free!) alternative in that case.

HTH

Share this post


Link to post
Share on other sites

  • 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!