Closed Psychobitch closed 8 years ago
First of all, the FILE API is not Windows only. Secondly, this has already been discussed, see #18.
Whoops that was my bad then, I was not meant to say windows only API.
Still the fact using old and deprecated functions isn't really innovative or a good way to teach newcomers.
As pointed out before: http://insanecoding.blogspot.se/2011/11/how-to-read-in-file-in-c.html
These results are rather interesting. There was no speed difference at all whether using the C or C++ API for reading a file. This should be obvious to us all, but yet many people strangely think that the C API has less overhead.
Simply imaginating that one is slower than the other at this point, is just delusional.
He said he benchmarked it though and it was faster for smaller files and slower for really big files(that he wasn't planning on having).
Also, why you do an if and then ASSERT(false,...)? Why not putting the if contents in the place you have the false?
To be fair, that is also an issue with the original code.
if (file == nullptr) SP_ASSERT(file, "Could not open file '", filepath, "'!");
should become
SP_ASSERT(file, "Could not open file '", filepath, "'!");
This will be eventually re-written in a platform specific FileSystem class; we won't be using FILE
anyway, so don't think too much into this. As for C-style FILE
vs C++ streams, FILE
does perform better than file streams, based on real-world experience.
Better to move away from using the old deprecated styles and use the C++ standards file system.