check if the memory is low, from Windows to Unix

Discussion in 'C Programming' started by kevin.heart@gmail.com, Jan 31, 2007.

  1. Guest

    Hi all,

    How to implement such function for Linux/Unix?

    /* sample begins*/
    #include "windows.h"
    ....
    MEMORYSTATUS stat;
    GlobalMemoryStatus(&stat);
    result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;
    ....

    if (result)
    trigger_low_mem_info();

    ....
    /* sample ends */

    Thanks!
    Kevin
     
    , Jan 31, 2007
    #1
    1. Advertising

  2. Lew Pitcher Guest

    On Jan 31, 8:40 am, wrote:
    > Hi all,
    >
    > How to implement such function for Linux/Unix?


    First off, as the C standard makes no mention of language facilities
    to determine "if memory is low" and does not specify operating system
    specific interfaces, your question is off-topic for comp.lang.c. You
    might want to ask in the comp.os.linux.development.apps newsgroup, or
    one of the other linux newsgroups. We can't help you here.

    Secondly, what makes you think that there /is/ a way to determine "if
    memory is low", or that such a measurement is meaningful or even
    necessary? My (experienced) guess is that you are trying to solve the
    wrong problem. When you ask in the Linux newsgroup, don't ask about
    specific functions. Instead, describe the problem you think you have
    (the one that, to you, necessitates that you measure whether or not
    "memory is low") and ask for help and advice on /that/ problem.
    Chances are that you'll get better advice than you would with "what
    function should I call" type questions.

    [snip]

    HTH
    --
    Lew
     
    Lew Pitcher, Jan 31, 2007
    #2
    1. Advertising

  3. CBFalconer Guest

    wrote:
    >
    > How to implement such function for Linux/Unix?
    >
    > /* sample begins*/
    > #include "windows.h"


    No such file in standard C.

    > ...
    > MEMORYSTATUS stat;


    No such macro or type has been defined.

    > GlobalMemoryStatus(&stat);
    > result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;


    undefined struct or union 'stat'. No such fields.

    > ...
    >
    > if (result)
    > trigger_low_mem_info();


    Undefined function.

    >
    > ...
    > /* sample ends */


    You neglected to include a description of 'such function'.
    Assuming you meant to include the subject line in the message, you
    find the memory is low when malloc (or calloc, or realloc) returns
    NULL.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
     
    CBFalconer, Jan 31, 2007
    #3
  4. Kenny McCormack, Jan 31, 2007
    #4
  5. santosh Guest

    wrote:
    > Hi all,
    >
    > How to implement such function for Linux/Unix?


    Try posting to comp.unix.programmer. Standard C has no support for
    determining memory usage.
     
    santosh, Jan 31, 2007
    #5
  6. Guest

    On Jan 31, 7:40 am, wrote:
    > Hi all,
    >
    > How to implement such function for Linux/Unix?
    >
    > MEMORYSTATUS stat;
    > GlobalMemoryStatus(&stat);
    > result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;



    As others have pointed out, this is OT for the group, but the above
    does not do what you appear to want, even under Windows. The page
    file size is dynamic (unless it's been explicitly fixed), so the ratio
    you're computing is basically meaningless.
     
    , Jan 31, 2007
    #6
    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.

Share This Page