CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    2

    How to find the free memory on windows

    Hi all,
    I am using new operator to allocate the memory
    and I want to use maximum free memory for my
    program without deleting previously allocated memory.

    After allocating some memory new throws
    bad_alloc exception for insufficient memory
    now I want to avoid this exception.
    So before allocating memory I have to check amount
    of free memory. I am using GlobalMemoryStatus to get
    the current free memory.

    new is throwing exception still GlobalMemoryStatus shows
    sufficient free memory which is more than I am trying to allocate.

    I am using Visual Studio 2005 for development .

    Is there any other way to check correct free memory..?

    Please help me..

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to find the free memory on windows

    Quote Originally Posted by iamvish View Post
    Is there any other way to check correct free memory..?
    Yes, and you are doing it - just use "new" to get what you want; if it fails - adjust your logic.
    What's wrong with getting bad_alloc?
    You need to know if you can allocate N bytes of memory, NOT if there is that much free memory (it can be fragmented).
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to find the free memory on windows

    Besides, though it seems off the topic, I'd recommend to review your memory allocation/deallocation design. Only once I ran into the memory insufficiency, for all these years.
    Best regards,
    Igor

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Re: How to find the free memory on windows

    There is a difference between the amount of free memory for the whole computer, and the amount of free memory for a process.

    Are you using a 32-bit version of Windows and do you want to allocate more than 2GB of memory?

    See "Memory Limits for Windows Releases" at http://msdn.microsoft.com/en-us/libr...78(VS.85).aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured