Thursday, September 2, 2010

Behind the 64MB limitation of ReadFileEx


Tip - If you use ReadFileEx API for reading a file in asynchronous mode in Windows XP 32bit OS, You cannot read more than 64MB (63.97 MB ) buffer in one API call.   Do you know why ?


Details - If you use this API in 32bit Operating System, you will get ERROR_NO_SYSTEM_RESOURCES error.  The reason for the ERROR_NO_SYSTEM_RESOURCES(1450) is that on x86 (32-bit) systems, the maximum buffer size is just under 64MB. For x64 systems, the maximum buffer size is just under 32MB.
The maximum unbuffered read and write size limits are imposed by the design of the IO manager inside the Windows executive.


The IO Manager uses the following formula to compute the maximum size MDL:


((65535 - sizeof(MDL)) / sizeof(ULONG_PTR)) * PAGE_SIZE


This formula has the following results:


Processor Page Size Pointer Size MDL calculation
======== ======== ========= =============
x86 (32-bit) 4096 4 bytes ((65535 - 28) / 4) * 4096 = 67076096 bytes (63.97 MB)
X64 4096 8 bytes ((65535 - 48) / 8) * 4096 = 33525760 bytes (32MB - 28K)


Reference - 

No comments:

Post a Comment