TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.1k stars 221 forks source link

Change FileUtils.cpp #65

Closed Psychobitch closed 8 years ago

Psychobitch commented 8 years ago

Better to move away from using the old deprecated styles and use the C++ standards file system.

PistonMiner commented 8 years ago

First of all, the FILE API is not Windows only. Secondly, this has already been discussed, see #18.

Psychobitch commented 8 years ago

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.

PedDavid commented 8 years ago

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?

PistonMiner commented 8 years ago

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, "'!");

TheCherno commented 8 years ago

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.