Jump to content
  • Advertisement
Sign in to follow this  
Alundra

C++ C++ Cross Platform Large File Support

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!