Question

I've been looking over the Doom 3 SDK code, specifically their File System implementation.

The system works (the code I have access to at least) by passing around an 'idFile' object and I've noticed that this class provides read and write methods as well as maintaining a FILE* member.

This suggests to me that either the FILE* is 'opened' with read and write access or the file is closed and reopened (with the appropriate access) between calls to Read() and Write().
Does this sound correct or am I over simplifying it?
If this isn't the case (which part of me suspects it isn't - due to speed etc.) does anyone have any suggestions as to how they would achieve this elegant interface?

Please bare in mind that I am fairly new to both C++ and stdio (which I'm pretty sure iD favours).

Was it helpful?

Solution

You can open a FILE* in read-write mode.

If you do that, you should flush and seek to a known location when changing between reading and writing, but you don't have to reopen the file.

OTHER TIPS

Without ever having looked at the Doom code (I'm guessing you can specify a mode when you create the object), you can use freopen() to re-open a file (in a different mode, if you want) without closing it first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top