x64 - WriteFile() - Insufficient system resources exist to completethe requested service.

Discussion in 'Windows 64bit' started by Michael Russell, Nov 1, 2005.

  1. 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
     
    Michael Russell, Nov 1, 2005
    #1
    1. Advertising

  2. Michael Russell

    Default User Guest

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

    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" <> wrote in message
    news:...
    >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
    >
    >
    >
     
    Default User, Nov 1, 2005
    #2
    1. Advertising

  3. Michael Russell

    Thor Olson Guest

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

    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" <> wrote in message
    news:...
    >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.
    >
     
    Thor Olson, Dec 11, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. serge

    Insufficient memory

    serge, Jul 16, 2003, in forum: Computer Support
    Replies:
    10
    Views:
    4,111
  2. pbdb

    Insufficient memory

    pbdb, Oct 10, 2003, in forum: Computer Support
    Replies:
    4
    Views:
    1,718
    Buffalo
    Oct 10, 2003
  3. mabra
    Replies:
    4
    Views:
    472
    mabra
    Jul 17, 2006
  4. Homer J. Simpson
    Replies:
    0
    Views:
    526
    Homer J. Simpson
    Aug 31, 2006
  5. Skybuck Flying
    Replies:
    13
    Views:
    2,883
    Skybuck Flying
    Jan 9, 2008
Loading...

Share This Page