I am not sure if this is the right place for this question or not. If not,
kindly direct me to the proper group.
I am having a problem with WriteFile() returning an error. I have whittled
this problem down to a short test program in C which fails under WinXP x64,
but works fine on WinXP x86. I see the problem whether I compile for a win32
or a win64 target. The quick summary is that if I use a size of 33525760 I
can use WriteFile() (after a CreateFile() with the FILE_FLAG_NO_BUFFERING
flag) just fine. If, however I use a file size of 33526272 or larger, then I get:
Insufficient system resources exist to complete the requested service.

I am running on a Dell Precision Workstation 670 w/ dual Xeon processors,
2GB RAM and using WinXP x64 SP1.
I have tried increasing the pagefile.sys size since someone suggested that,
but it did not help.

Here's the sample code:

--- CUT HERE - start of cf-test.cpp ---
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <Windows.h>

// Forward Declaration
void PrintError (void);

int main(int argc, char *argv[])
{
HANDLE hHandle = NULL;
char caFilename[512];
bool bRet = false;
unsigned char *ucpData = NULL;
// This size will work
// long lChunkSizeBytes = 33525760;
// This size will NOT work
long lChunkSizeBytes = 33526272;
unsigned long ulNumBytesWritten = 0;
printf("argc = %d\n", argc);

if (argc > 1)
sscanf(argv[1], "%ld", &lChunkSizeBytes);

strcpy(caFilename, "test.dat");

// Allocate Memory
printf("Allocating memory (%ld bytes)...\n", lChunkSizeBytes);
ucpData = (unsigned char *) VirtualAlloc(NULL,
lChunkSizeBytes,
MEM_COMMIT,
PAGE_READWRITE);
printf("done.\n");

// Open File
printf("Opening file '%s'...\n", caFilename);
hHandle = CreateFile(caFilename,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_FLAG_NO_BUFFERING,
NULL);

if (hHandle == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "Error Opening File\n");
PrintError();
//MemoryFree(&hMem, &ucpData);
exit(-1);
}
printf("done, handle = 0x%x.\n", hHandle);

// Write File
printf("Writing file...\n");
if (!WriteFile(hHandle, ucpData, lChunkSizeBytes, &ulNumBytesWritten,
NULL))
{
fprintf(stderr, "Error Writing File\n");
PrintError();
//MemoryFree(&hMem, &ucpData);
exit(-1);
}
printf("done.\n");

// Close File
printf("Closing file...\n");
if (!CloseHandle(hHandle))
{
fprintf(stderr, "Error Closing File\n");
PrintError();
//MemoryFree(&hMem, &ucpData);
exit(-1);
}
printf("done.\n");

// Free Memory
printf("Releasing Memory...\n");
if (!VirtualFree(ucpData, 0, MEM_RELEASE))
{
fprintf(stderr, "Error Freeing Memory\n");
PrintError();
//MemoryFree(&hMem, &ucpData);
exit(-1);
}
printf("done.\n");
}

void PrintError (void)
{
LPVOID lpMsgBuf;

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);

// Display the error number & string
fprintf(stderr, " GetLastError(0x%x) = %s\n", GetLastError(),
(LPCTSTR) lpMsgBuf);

// Free the buffer.
LocalFree(lpMsgBuf);
return;
}
--- CUT HERE - end of cf-test.cpp ---

Compilation for x64 is done with the Platform SDK for Windows Server 2003 SP1
and selecting the Build Environment for XP x64 Retail. Then "cl cf-test.cpp
bufferoverflowU.lib". Thanks very much for any assistance.

-Michael Russell
russell@mathtech.com

Re: x64 - WriteFile() - Insufficient system resources exist to complete the requested service. by Default

Default
Tue Nov 01 15:28:14 CST 2005

Here are some of the groups you can try:
microsoft.public.vc.ide_general
microsoft.public.vc.debugger
microsoft.public.vc.mfc
--
Andre
Extended64 | http://www.extended64.com
Blog | http://www.extended64.com/blogs/andre
http://spaces.msn.com/members/adacosta
FAQ for MS AntiSpy http://www.geocities.com/marfer_mvp/FAQ_MSantispy.htm
"Michael Russell" <russell@mathtech.com> wrote in message
news:Oy2p6rx3FHA.1188@TK2MSFTNGP12.phx.gbl...
>I am not sure if this is the right place for this question or not. If not,
>kindly direct me to the proper group.
> I am having a problem with WriteFile() returning an error. I have
> whittled this problem down to a short test program in C which fails under
> WinXP x64, but works fine on WinXP x86. I see the problem whether I
> compile for a win32 or a win64 target. The quick summary is that if I use
> a size of 33525760 I can use WriteFile() (after a CreateFile() with the
> FILE_FLAG_NO_BUFFERING flag) just fine. If, however I use a file size of
> 33526272 or larger, then I get:
> Insufficient system resources exist to complete the requested service.
>
> I am running on a Dell Precision Workstation 670 w/ dual Xeon
> processors, 2GB RAM and using WinXP x64 SP1.
> I have tried increasing the pagefile.sys size since someone suggested
> that, but it did not help.
>
> Here's the sample code:
>
> --- CUT HERE - start of cf-test.cpp ---
> #include <stdio.h>
> #include <io.h>
> #include <fcntl.h>
> #include <Windows.h>
>
> // Forward Declaration
> void PrintError (void);
>
> int main(int argc, char *argv[])
> {
> HANDLE hHandle = NULL;
> char caFilename[512];
> bool bRet = false;
> unsigned char *ucpData = NULL;
> // This size will work
> // long lChunkSizeBytes = 33525760;
> // This size will NOT work
> long lChunkSizeBytes = 33526272;
> unsigned long ulNumBytesWritten = 0;
> printf("argc = %d\n", argc);
>
> if (argc > 1)
> sscanf(argv[1], "%ld", &lChunkSizeBytes);
>
> strcpy(caFilename, "test.dat");
>
> // Allocate Memory
> printf("Allocating memory (%ld bytes)...\n", lChunkSizeBytes);
> ucpData = (unsigned char *) VirtualAlloc(NULL,
> lChunkSizeBytes,
> MEM_COMMIT,
> PAGE_READWRITE);
> printf("done.\n");
>
> // Open File
> printf("Opening file '%s'...\n", caFilename);
> hHandle = CreateFile(caFilename,
> GENERIC_WRITE,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> NULL,
> OPEN_ALWAYS,
> FILE_FLAG_NO_BUFFERING,
> NULL);
>
> if (hHandle == INVALID_HANDLE_VALUE)
> {
> fprintf(stderr, "Error Opening File\n");
> PrintError();
> //MemoryFree(&hMem, &ucpData);
> exit(-1);
> }
> printf("done, handle = 0x%x.\n", hHandle);
>
> // Write File
> printf("Writing file...\n");
> if (!WriteFile(hHandle, ucpData, lChunkSizeBytes,
> &ulNumBytesWritten,
> NULL))
> {
> fprintf(stderr, "Error Writing File\n");
> PrintError();
> //MemoryFree(&hMem, &ucpData);
> exit(-1);
> }
> printf("done.\n");
>
> // Close File
> printf("Closing file...\n");
> if (!CloseHandle(hHandle))
> {
> fprintf(stderr, "Error Closing File\n");
> PrintError();
> //MemoryFree(&hMem, &ucpData);
> exit(-1);
> }
> printf("done.\n");
>
> // Free Memory
> printf("Releasing Memory...\n");
> if (!VirtualFree(ucpData, 0, MEM_RELEASE))
> {
> fprintf(stderr, "Error Freeing Memory\n");
> PrintError();
> //MemoryFree(&hMem, &ucpData);
> exit(-1);
> }
> printf("done.\n");
> }
>
> void PrintError (void)
> {
> LPVOID lpMsgBuf;
>
> FormatMessage(
> FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
> NULL,
> GetLastError(),
> MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
> (LPTSTR) &lpMsgBuf,
> 0,
> NULL
> );
>
> // Display the error number & string
> fprintf(stderr, " GetLastError(0x%x) = %s\n", GetLastError(),
> (LPCTSTR) lpMsgBuf);
>
> // Free the buffer.
> LocalFree(lpMsgBuf);
> return;
> }
> --- CUT HERE - end of cf-test.cpp ---
>
> Compilation for x64 is done with the Platform SDK for Windows Server 2003
> SP1 and selecting the Build Environment for XP x64 Retail. Then "cl
> cf-test.cpp bufferoverflowU.lib". Thanks very much for any assistance.
>
> -Michael Russell
> russell@mathtech.com
>
>


Re: x64 - WriteFile() - Insufficient system resources exist to complete the requested service. by Thor

Thor
Sun Dec 11 10:32:06 CST 2005

We are seeing a similar problem on Windows Server 2003 Enterprise (x64).
The configuration is dual Opterons with 8GB of memory. In our case, the
problem is occurring in programs doing very large reads. As in Michael's
case, the applications run without error on 32-bit systems. The problem
does not appear to be related to Visual C++. At our site, it is happening
with both VC and IBM Visual Age PL/I applications.

"Michael Russell" <russell@mathtech.com> wrote in message
news:Oy2p6rx3FHA.1188@TK2MSFTNGP12.phx.gbl...
>I am not sure if this is the right place for this question or not. If not,
>kindly direct me to the proper group.
> I am having a problem with WriteFile() returning an error. I have
> whittled this problem down to a short test program in C which fails under
> WinXP x64, but works fine on WinXP x86. I see the problem whether I
> compile for a win32 or a win64 target. The quick summary is that if I use
> a size of 33525760 I can use WriteFile() (after a CreateFile() with the
> FILE_FLAG_NO_BUFFERING flag) just fine. If, however I use a file size of
> 33526272 or larger, then I get:
> Insufficient system resources exist to complete the requested service.
>
> I am running on a Dell Precision Workstation 670 w/ dual Xeon
> processors, 2GB RAM and using WinXP x64 SP1.
> I have tried increasing the pagefile.sys size since someone suggested
> that, but it did not help.
>