Available Physical Memory
- From: chsalvia@xxxxxxxxx
- Date: Sat, 16 Jun 2007 04:29:05 -0000
A few weeks ago I posted here asking how an application could
determine the available memory on a machine running some variety of
UNIX. There were basically two types of responses:
1. Those who scoffed at the very idea, saying that "available memory"
was too vague of a term and that no application should ever need to
know that anyway because it's exclusively the kernel's business.
2. Those who disagreed saying that there are some situations where a
program legitimately needs to know the available memory.
I'd agree with the 2nd category, but I'd rephrase the question to say:
"is there a way to determine the available physical memory on a UNIX
system?"
Apparently there is, at least on Linux. You can do something like:
size_t av_phys_mem = sysconf(_SC_AVPHYS_PAGES) *
sysconf(_SC_PAGESIZE);
I would also argue that there are legitimate reasons an application
may need to know the available memory.
1. Firstly, if the program itself is *designed* to report the
available system memory to the user, like top or atop. (granted this
is a rare scenario)
2. If the program runs on a dedicated server/work-station and is
designed to perform a specific task, like sort massive amounts of
data.
To expand on number 2, suppose you need to periodically merge-sort
files that exceed 1 terabyte in size. In order to do this, you'd want
the computer to use *ALL* the memory it can. Therefore you have two
options: either hard code the amount of memory it uses, or somehow get
the available physical memory. It seems obvious to me that the latter
option is more desirable and more practical.
Am I wrong? If so, why?
.
- Follow-Ups:
- Re: Available Physical Memory
- From: Rainer Weikusat
- Re: Available Physical Memory
- From: Gordon Burditt
- Re: Available Physical Memory
- From: David Schwartz
- Re: Available Physical Memory
- From: Eric Sosman
- Re: Available Physical Memory
- Prev by Date: Re: Solving the lib mismatch problem
- Next by Date: Re: which UNIX for programming job ?
- Previous by thread: Solving the lib mismatch problem
- Next by thread: Re: Available Physical Memory
- Index(es):
Relevant Pages
|