PDA

View Full Version : c++ reading files from disk


Ian Jones
05-30-2007, 02:29 PM
I do not have formal programming training in many areas, and am self teaching atm. I am wondering if constantly reading a file (well sequential files like frames for example) 30 times a second from a harddrive is safe?

My concern is of course harddrive errors or even failure. Whats the common understanding with this? Surely there are areas of a hard disk which get hammered through normal use, but is my case particularily unusual and bad for the drive?

I am testing openGL video texturing and am using sequential pngs atm, but will move onto proper vide codecs very soon using libavcodec.

Robert Bateman
05-30-2007, 03:03 PM
Read them once, store them as openGL textures and flip through them by binding to a different texture object. Generally trying to read files for every rendered frame is a bad idea.

Ian Jones
05-30-2007, 10:28 PM
yeh, I am definitely avoiding it in anything but test code but I'm wondering about the potential harms to a hdd doing this?

stew
05-30-2007, 10:56 PM
In most cases, OS will cache file reading anyway.

mummey
05-30-2007, 10:56 PM
yeh, I am definitely avoiding it in anything but test code but I'm wondering about the potential harms to a hdd doing this?

Mostly its speed. Reading from a harddrive is very slow. A good chuck of the time in a read is the starting and stoping so you want to do it as few times as reasonable.

Ian Jones
05-31-2007, 09:07 AM
Interesting, I didnt realise an OS would cache loaded files but it makes heaps of sense.

billrobertson42
06-04-2007, 03:44 AM
You will get some mileage out of OS level read caching but not much. Most IO libraries (e.g. stdio) have read buffering built in though so it's usually not a huge worry.

Robert Bateman is right. Read all of them, and flip through them in memory. If you have (or could have) thousands of frames then you might want to write code to read chunks of them in ahead of time and while you're flipping through the ones in memory begin reading the next batch. Memory mapping is a nice option if you have to do this sort of thing.

Ian Jones
06-04-2007, 09:30 AM
Yep, I'll be implementing what you have described. Is this what you refer to as a memory mapper?

CGTalk Moderation
06-04-2007, 09:30 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.