IReadFile - Should it really force a user to open a file?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

IReadFile - Should it really force a user to open a file?

Post by Halifax »

Well this seems a little disturbing to me. IReadFile does not allow you to close a file by yourself, it does it in the destructor, and it doesn't allow you to create an IReadFile to read multiple files. This doesn't necessarily follow the rules of a FILE, and it also doesn't allow a user to free up memory if it isn't used anymore, and forces them to use more memory if they don't plan on reading files sequentially.

My proposal is the take the opening and closing out of the constructor and destructor, respectively. Then add those to functions named openFile(), and closeFile(). This would allow the user to read multiple files with only one IReadFile, e.g.:

Code: Select all

IReadFile* myFile;
myFile->openFile("test.txt");
myFile->closeFile();
myFile->openFile("test2.txt");
myFile->closeFile();
instead of

Code: Select all

IReadFile* myFile = new IReadFile("test.txt");
IReadFile* myFile2 = new IReadFile("test2.txt");
... etc ...
IReadFile* myFile = new [/code]
TheQuestion = 2B || !2B
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Hmm wouldn't that tie the interface to actual physical files, or force it to have a link to the IFileSystem?
For example, openFile and close have no meaning on a memory file, like if it exists inside a zip file and the memory was allocated by the zip loader.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Moreover, IReadFile does not mean IFileReader. It's just one file, you can read it. If you want to read another file, create another IReadFile. No memeory overhead, because you can close the first one. Only minor allocation/deallocation, but neglectable when looking at reading times of the actual file.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Alright, fair enough, thanks for explaining.
TheQuestion = 2B || !2B
Post Reply