473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

check if the memory is low, from Windows to Unix

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 '07 #1
5 2112
On Jan 31, 8:40 am, kevin.he...@gmail.com 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
Jan 31 '07 #2
In article <11**********************@v33g2000cwv.googlegroups .com>,
<ke*********@gmail.comwrote:
>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

Jan 31 '07 #3
ke*********@gmail.com 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>
Jan 31 '07 #4
ke*********@gmail.com 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.

Jan 31 '07 #5
On Jan 31, 7:40 am, kevin.he...@gmail.com 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 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
14
by: S Green | last post by:
Does any one now if a shared memory module exists, written in python for a windows platform. I now one exists for unix? help most appreciated, S Green
3
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
2
by: Janice | last post by:
How to obtain the lock status of a file held by other process? If I read the file that is locked by other process, the read would return -1. If the file is locked by other process, how to put the...
11
by: noleander | last post by:
Ive got a time-critical application that runs on Windows XP and Unix. I've got some timing issues that Ive traced to virtual memory getting paged in and out. I think I can solve the problem if...
3
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the...
4
by: FFMG | last post by:
Hi, My Hosting company is saying that I am using too much memory on the VPS and that I should upgrade. I am currently running at 65%-75%, (according to WHM). It does seem a bit high, but I...
13
by: Jim Langston | last post by:
I had asked this in comp.lang.c++ with out any answers that would actually work, so I'm hoping someone here may know a way. I am calling C library functions that want to output to stdout. I need...
11
by: richi | last post by:
Hi everyone, I am sorry, my english is not good! I found a problem about memory. In a function I malloced more memory than before that is 4.5625Kb in theory. Then I watched the memory size of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.