Reading Large Binary File

I'm trying to read a large (~1.3 Gig) binary file, but I get stuck allocating memory to the buffer. Here is a fragment of the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
	//Initialize error_code
	error_code = 0;

	//Get the file size
	DWORD dwBSize = MyFileOps.get_file_size(ThisFile);

	//Check for minimimum file size
	if(dwBSize < MIN_RAW_SIZE) {error_code = -1; return 0;}

	//Declare the buffer that will hold the raw file info
	unsigned char *rBuffer = NULL;

	//Allocate memory to rBuffer
	rBuffer = new (nothrow) unsigned char[dwBSize];
	if(NULL == rBuffer) {error_code = -2; return 0;}

	//Load the file into memory
	if(!MyFileOps.load_file(ThisFile, rBuffer, dwBSize))
	{
		delete [] rBuffer; rBuffer = NULL;
		error_code = -3;
		return 0;
	}


The program returns with error_code = -2; meaning it could not allocate memory to the buffer. I made a class that is associated with all file transactions; such as determining the file size using "GetFileSize", reading the file using "ReadFile." The code above is for a GUI interface with classes. I re-wrote the program with a traditional DOS interface using the same WIN API functions, but without a class and was able to read the file (although it took some time). Any help is greatly appreciated.

Thanks,

DominicanJB
Last edited on
I could be wrong, but I don't think there's really any way to allocate that much memory in one block, there's only so much you can keep on one contiguous section.
Last edited on
Topic archived. No new replies allowed.