Click to See Complete Forum and Search --> : ReadFile (win32 API) cannot read more than 64 MB
serio
January 31st, 2005, 09:56 PM
Hi to all members.
I have a little "c" program to read bytes from a hard drive. It works perfectly fine as long as the "nNumberOfBytesToRead" parameter in the ReadFile function (win32 API) is less than 64 MB. Anything bigger than that, results in the ReadFile function returning 0 (zero) indicating a failure of that function.
Could anybody put some light on this.
Many thanks to all,
Serge Matovic.
NigelQ
January 31st, 2005, 11:15 PM
64MB is a large chunk of memory. The first question may be to determine how you are allocating such a chunk, and whether this is successful.
Obviously a call to GetLastError after your call to ReadFile should indicate the exact nature of the problem.
Hope this helps,
- Nigel
serio
February 1st, 2005, 10:17 AM
Thanks Nigel:
Here are the items you requested:
1) The error code, repoted by the GetLastError() function is 1450, and Msft site says this about it: "ERROR_NO_SYSTEM_RESOURCES Insufficient system resources exist to complete the requested service."
2) My memory allocation code is:
lpSectBuff=
(LPBYTE)VirtualAlloc(NULL,102400000,MEM_COMMIT,PAGE_READWRITE);
3) My ReadFile function is:
fResult=
ReadFile(hDev,lpSectBuff,nNumberOfBytesToRead,lpNumberOfBytesRead,NULL);
My PC has 512 MB RAM, 80 GB hard drive, and Windows 2000 Prof.
As I mentioned, my code works perfectly as long as nNumberOfBytesToRead<64MB
Many thanks.
indiocolifa
February 16th, 2005, 04:01 PM
Use file-mapping: you can load only the part of the file you want to "view" (or process). This manner, you can for example, create a text editor and load a 100MB file and only view the first kbytes if you need.
FROM MSDN:
File mapping is the association of a file's contents with a portion of the virtual address space of a process. The system creates a file mapping object to maintain this association. A file view is the portion of virtual address space that the process uses to access the file's contents. Processes read from and write to the file view using pointers, just as they would with dynamically allocated memory. Processes can also manipulate the file view with the VirtualProtect function. File mapping provides two major advantages:
Faster and easier file access
Shared memory between two or more applications
For this, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/file_mapping.asp
May be this can help...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.