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

    Arrow My program is hungry for memory

    I have to allocate memory for my variables
    I have to use malloc
    it works
    Only that I wonder what if I no longer have more memory to offer ? what happen during the request being proess?


    Thank you

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: My program is hungry for memory

    If you run out of physical RAM, most OSes will begin swapping out portions of the address space to disk. This is fine if the swapped out portions of memory won't be needed for a while; but if you are frequently accessing all parts of memory, then you can get excessive swapping, called thrashing, which could slow down your program by 100x or more.

    If you run out of address space----which usually happens between 1.5 and 2GB of allocation in a 32-bit process, regardless of how much physical RAM you have----then malloc() will simply fail and return NULL. If you're using new instead of malloc, then it may throw an exception instead.

    The majority of programs do not require so much memory that this is a problem. Usually, running out of memory means that you aren't managing it correctly.

  3. #3
    Join Date
    Jun 2010
    Posts
    50

    Re: My program is hungry for memory

    You may want to read McKusick's paper for Linux memory management

  4. #4
    Join Date
    Jul 2010
    Posts
    94

    Re: My program is hungry for memory

    Thanks, Lindley for details

    @TheComputer, thanks I find a lot of McKusick on google search

  5. #5
    Join Date
    Jul 2010
    Posts
    94

    Re: My program is hungry for memory

    @TheComputer, but sad McKusick only states little information about what I am doing, not really correct about what I am doing

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: My program is hungry for memory

    If this is a real situation, you may want to rethink your program design.

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