Link to home
Start Free TrialLog in
Avatar of ormale67
ormale67

asked on

open a very huge file (48 GB) in C++ or C

I need open a very huge file and until now I could not open it!
So I need help about it.    The characteristics of my PC are: 2GB RAM, 2.99 GHz, I am compiling with Visual C++ and OS is Windowd

main()
{

  char *path1 = "C:\\Reconstruction\\quad-HIDAC_data\\Test_File.lst";
  char buffer[1024];

  fstream fin;   // object from fstream class

  fin.open(path1,ios::binary,ios::in);
 
  if(!fin.is_open())
  {
        cout << "Fail....";
        return 0;
  }
  else
  {
 
    // do somthig


     fin.close();
  }

}
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ormale67
ormale67

ASKER



I will complie this code,

thanks !

I recommend that you also use MapFile API function in addition to CreateFile API function.

That will speed up your code when reading and writing.
I already answer this question, and this is the code that could work for open a huge file:  This example was found
with the help of Visual C++ 6.0.

/* OPEN.C: This program uses _open to open a file
 * named OPEN.C for input and a file named OPEN.OUT
 * for output. The files are then closed.
 */

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>

void main( void )
{
   int fh1, fh2;

   fh1 = _open( "OPEN.C", _O_RDONLY );
   if( fh1 == -1 )
      perror( "open failed on input file" );
   else
   {
      printf( "open succeeded on input file\n" );
      _close( fh1 );
   }

   fh2 = _open( "OPEN.OUT", _O_WRONLY | _O_CREAT, _S_IREAD |
                            _S_IWRITE );
   if( fh2 == -1 )
      perror( "Open failed on output file" );
   else
   {
      printf( "Open succeeded on output file\n" );
      _close( fh2 );
   }
}