Skip to main content
gamedev.net
🔒 Locked

Quick fstream question

Started by MutteringGoblin 1 reply 300+ views
Original Post
MutteringGoblin
MutteringGoblin
Hello, I noticed fstream has a function which reads a single byte from a file. Is is significantly slower to read a file in this way? Thanks
JohnBolton
JohnBolton
The AP is wrong. The right answer is dependent on the OS, the application, and the device. Reading a byte at a time is frequently not slower -- the OS will usually load an entire sector anyway (not just one byte). When you read the next byte, the OS has already loaded it and just hands it to you.

It is generally not faster to load an entire 100 MB file unless your computer has plenty of RAM. As you are loading in those last megabytes, free RAM will be getting low and the OS is going to swap your data out to the disk. Then you start parsing at the beginning and the OS has to swap that data in and swap the data that was just loaded out. The total is 4 disk accesses for each page of memory in the file ( 1 read, 2 swap-outs and 1 swap-in).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.