1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Out of virtual memory?

Discussion in 'Win32' started by wlof, Aug 28, 2010.

  1. wlof

    wlof New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    Hello everyone,

    I have a problem with an application. It establishes a bunch (between 5 and 100) of client connections, plus 2 server connections, to other applications and sends, receives and processes commands using these connections. Each connection has its own thread. There are also a few other threads dedicated to processing, and the application frequently creates temporary threads that serve a simple timer purpose (all they do is Sleep(), send a signal, and terminate).

    For a stress test, I repeatedly closed and reestablished one of the connections (doesn't matter which one). After a while (a few hundred times), my application started expecting strange behavior. Further investigation showed that the application was unable to connect sockets (calls to connect() systematically fail with error code WSAENOBUFS) and create new threads (calls to CreateThread() systematically fail with error ERR_NOT_ENOUGH_MEMORY).

    I added a snipet of code to call GlobalMemoryStatus() when CreateThread() fails, and here is the output:
    The MemoryStatus structure is 32 bytes long. It should be 32.
    26 percent of memory is in use.
    There are 2138554368 total bytes of physical memory.
    There are 1577644032 free bytes of physical memory.
    There are 4125798400 total bytes of paging file.
    There are 3577077760 free bytes of paging file.
    There are 2147352576 total bytes of virtual memory.
    There are 11612160 free bytes of virtual memory.
    So it seems my app is running out of virtual memory. What could cause this? Common memory leaks? Or something more subtle?

    Sorry if I'm not being very clear, English is not my first language and the exact problem is hard to describe without explaining every inner working of the app. Basically I'm looking for any tips as to what causes my app to run out of virtual memory.

    Thanks in advance!

Share This Page