Open Large Files in C++
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Open Large Files in C++

Hybrid View

  1. #1
    Join Date
    Jun 2010
    Posts
    136

    Open Large Files in C++

    Hi,
    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.

    Regards,
    Abhishek Madaan

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,765

    Re: Open Large Files in C++

    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).

  3. #3
    Join Date
    Jun 2010
    Posts
    136

    Re: Open Large Files in C++

    Hi OReubens,
    Thanks for your reply. Unfortunately, I can't move to 64-bit system yet. Is it possible to read/write data from/to the file in 32-bit system which is larger than 4GB?

    Regards,
    Abhishek Madaan

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Open Large Files in C++

    Using 64 bit integers has no dependance on bitness of your system. Though without seeing your code how you do writing it's not possible for us to make any suggestion on code improvement.
    Best regards,
    Igor

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,765

    Re: Open Large Files in C++

    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.

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,266

    Re: Open Large Files in C++

    The only small piece of advice I can offer is to look at chapter 10 of 'Windows via c/c++ 5th edition' by Jeffrey Richter where he discusses using files greater than 4gb.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center