?
Solved

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

Posted on 2004-10-08
5
Medium Priority
?
206 Views
Last Modified: 2012-08-13
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();
  }

}
0
Comment
Question by:ormale67
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 375 total points
ID: 12261416
A file of that size will fail because of the 32bit size limit. You'll have to use the Win32 API to access it, e.g.

#include <windows.h>

void main () {


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

 HANDLE  hFile = CreateFile ( path1, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

 while ( 1) {

  ReadFile ( hFile, buffer, 1024, &dwRead, NULL);

  // ...
 }

 CloseHandle ( hFile);
}
0
 

Author Comment

by:ormale67
ID: 12261460


I will complie this code,

thanks !

0
 
LVL 30

Expert Comment

by:Axter
ID: 12262338
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.
0
 

Author Comment

by:ormale67
ID: 12652949
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 );
   }
}
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question