check if the memory is low, from Windows to Unix

K

kevin.heart

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
 
L

Lew Pitcher

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
 
C

CBFalconer

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.
 
R

robertwessel2

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top