get available RAM

Discussion in 'Mac Programming' started by john903, Aug 31, 2009.

  1. john903 macrumors member

    Joined:
    Apr 11, 2008
    #1
    How do you get the available RAM remaining in a carbon app?
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    The definition of "available ram" is not at all clear on a modern system. Would the contents of purgeable memory count as "available"? It's in use, but will be cleared as soon as there's any memory pressure. What about mmap()'d files?
     
  3. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #3
    Activity Monitor lists "Free System Memory". This is the value I want to get in my app.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    What do you intend to do with this value once you have it? Be specific.
     
  5. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #5
    I would grab the source for the 'top' command and see how it gets its information.
     
  6. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #6
    What does that matter? I just want to get the value! :D

    What do you mean by the top command?

    All I want is some magical function like GetFreeMemoryInMegabytes.
     
  7. Cinder6 macrumors 6502

    Cinder6

    Joined:
    Jul 9, 2009
    #7
  8. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #8
    top is a unix utility that (among other things) lists free ram; like most of the unix layer of OSX, it's open source. Therefore, you can read its code to find out how to do it.
     
  9. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #9
    It matters because the people that you are depending on to be smarter than you (hence you asking them questions), are smarter than you and know that this value is relatively meaningless on MacOS X (at least the non-iPhone version).

    In general when you are looking for help you should start out explaining what you are trying to do (broad strokes) then describe your specific question. More often than not the reason you can't seem to do what you think you need to do is because you don't understand what is going on. Thus you need to accept that other people need more information than you might think.
     
  10. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #10
    Cinder6: Thank you!!! Works perfect and was just what I was looking for.

    larkost: I didn't mean to sound rude but it's for a complicated project so it would be to hard to explain.

    Thanks for the help!
     

Share This Page