[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 How can I tell how much memory my system has?

This is another `Frequently Unanswered Question'. In most cases, you should not even attempt to find out.

If you really must, then it can usually be done, but in a highly system-dependent fashion. For example, on Solaris, you can use sysconf(_SC_PHYS_PAGES) and sysconf(_SC_PAGESIZE); on FreeBSD, you can use sysctl(); on Linux you can read and parse ‘/proc/meminfo’ (being careful to allow any of the historically valid formats for this file); other systems may have their own methods. I'm not aware of any more portable methods.

For HP-UX (9 and 10), the following code has been contributed:

 
struct pst_static pst;

if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1)
{
    printf(" Page Size: %lu\n", pst.page_size);
    printf("Phys Pages: %lu\n", pst.physical_memory);
}

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated on September, 10 2007 using texi2html 1.77.