Microsoft KB Archive/98893

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), included with:
 * Microsoft Windows NT 3.1

-

SUMMARY
There is a limit to the number of bytes that can be written with WriteFile using asynchronous I/O (FILE_FLAG_OVERLAPPED specified). This limit depends on the size of your system.

Asynchronous (overlapped) I/O consumes system resources for a long time. For example, the memory used is locked in the process working set until the I/O completes. To limit the amount of system resources used asynchronously by an application, the system charges asynchronous I/O to the working set of the process requesting the I/O.

While the working set size is dynamically raised and lowered based on the load, there are minimum and maximum values. These values are based on system size: consider up to 12 megabytes (MB) a small system, between 12 MB and 19 MB a medium system, and greater than 19 MB a large system. Each process is guaranteed a minimum working set for performance reasons; about 120K for small systems, 160K for large systems, and 245K for large systems.

When system resources are heavily taxed, a process is confined to its maximum working set. Asynchronous I/Os may never cause you to exceed your maximum working set, because once you are allowed to initiate an asynchronous I/O, the page cannot be taken away if memory becomes tight. The maximum working set sizes are about 300K for a small system, 716K for a medium system, and 1.5 MB for a large system.

MORE INFORMATION
The following code can be used to experiment with the maximum number of bytes that can be written using asynchronous I/O. Simply change the line to vary the number of bytes that the code attempts to write:

"#define NBR_BYTE 700000"

Sample Code
#include 
 * 1) include 
 * 2) include 
 * 3) include 


 * 1) include 


 * 1) define NBR_BYTE 700000

int main(void) {  char        *c; HANDLE     hFile; DWORD      byteWrite; OVERLAPPED overLap; DWORD      err; BOOL       result;

c = malloc( NBR_BYTE ); assert( c != NULL );

overLap.hEvent = CreateEvent( NULL, FALSE, FALSE, &quot;event1&quot; ); assert( overLap.hEvent );

hFile = CreateFile( &quot;test&quot;, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,                       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |                       FILE_FLAG_WRITE_THROUGH,                       NULL);

if( hFile == INVALID_HANDLE_VALUE ) {     free( c ); printf( &quot;error opening file\n&quot; ); exit( 0 ); }

overLap.Offset    = 0; overLap.OffsetHigh = 0; result = WriteFile( hFile, c, NBR_BYTE, &byteWrite, &overLap ); if( result == FALSE ) {     err = GetLastError; if( err != ERROR_IO_PENDING ) {        free( c ); printf( &quot;Error: %d\n&quot;, GetLastError ); exit( 0 ); }  }

free( c );

return 0; } Additional query words: 3.10 asynch

Keywords         : Version          : winnt:3.1 Platform         : winnt Issue type       :
 * }