🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ Cross Platform Large File Support

Started by
2 comments, last by Shaarigan 4 years, 8 months ago

Hello!
What is the best way to handle large file support on Windows/Linux/Mac/Android/IOS?
Is it good to handle large file support also on x86 or only x64?
The problem is ftell and fseek which use long as parameter and not size_t...
Is the best practice to use _fseeki64 + _ftelli64 for Windows and fseeko + ftello for other platforms?
fseeko and ftello needs _FILE_OFFSET_BITS to be defined as 64: #define _FILE_OFFSET_BITS 64.
Thanks!

Advertisement

The best way is likely not to have large files.

If you must, you can also seek relatively, wouldn't that solve your problem? You can track the position yourself, no need to use ftell.

 

You can build your custom solution using the OS specific APIs, the major ones (I don't know about Apple) support large files by default. Windows for example takes two parameters, a low part and a high part integer to address files larger than int.max bytes but even Unix should have some API you could use and so Linux/Android have. The other option is to use memory mapped files, this has the advantage to load only a few bytes into an OS page that will be swapped in on demand and all you have to do is to offset a pointer.

I was involved in a custom database system and we were able to address 40 bit, up to 4 TB of space in a single file using memory mapping and a clever chunk management

This topic is closed to new replies.

Advertisement