Limit on the Number of Bytes Written AsynchronouslyLast reviewed: November 2, 1995Article ID: Q98893 |
The information in this article applies to:
SUMMARYThere 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 INFORMATIONThe 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 <stdio.h> #include <stdlib.h> #include <malloc.h> #include <assert.h> #include <windows.h> #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, "event1" ); assert( overLap.hEvent ); hFile = CreateFile( "test", 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( "error opening file\n" ); 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( "Error: %d\n", GetLastError() ); exit( 0 ); } } free( c ); return 0;}
|
Additional reference words: 3.10 asynch
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |