I would need help on opening large files in c++. In my application, i am trying to save video as long as users have space in harddisk. What I am trying to do is when user is recording video i am trying to append the video data in to the file. The problem is that every time file size reach over 2GB my software crashes. I looked online but couldn't find any suitable solution to my problem. I am working on VC++ on Windows.
If someone can help me related to this matter that would be really appreciated.
looks like you are using 32bit integers to do 'something' with your file (seeks, locks, filesize, ...) but a 32bit int can only hold a value from -2billion to +2billion.
You'll need to change your code to use 64bit integers.
Also, it's posible that whatever API's/ libraries or whatever you're using don't support files above 2Gb in size.
Also, if you use memorymapping, then you can't map a bigger file than the amount of available memory in your process, which is 2gb at best (minus whatever is taken by system dll's, and accounting for memory fragmentation).
you can read a file larger than 4gb with Win32 using 32bit code but...
you can't read all the file at once, you'll have to read it in smaller chunks and process each of the smaller chunks.
Win32 only allow you a max of 2gb (3gb with some messing around) per process, and part of that will be already used bb system DLL's and will be fragmented.
If you do seeks, get the file size, try to lock parts of the file, you will need to use 64bit integers, and yes, you can do this in Win32.
Some libraries/api functions/objects don't support files larger than 2gb. (or 4gb if they use unsigned integers) This could be your problem, but we have no way of knowing since you haven't told what you're using/doing.