Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > check if the memory is low, from Windows to Unix

Reply
Thread Tools

check if the memory is low, from Windows to Unix

 
 
kevin.heart@gmail.com
Guest
Posts: n/a
 
      01-31-2007
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

 
Reply With Quote
 
 
 
 
Lew Pitcher
Guest
Posts: n/a
 
      01-31-2007
On Jan 31, 8:40 am, (E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      01-31-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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>


 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      01-31-2007
In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:
>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;
>...


Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      01-31-2007
(E-Mail Removed) 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.

 
Reply With Quote
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      01-31-2007
On Jan 31, 7:40 am, (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to check for unix password eight02645999@yahoo.com Python 4 11-02-2005 05:00 PM
Win32 or Unix check in python GujuBoy Python 1 03-29-2005 04:14 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM



Advertisments