This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Call for testers: libiberty/physmem.c


In article <20030221174040 dot GA80208 at antares dot student dot iastate dot edu> you write:
>Here is a sample code that works on FreeBSD-STABLE.  The values returned
>by sysctl are said to be in bytes and so I don't know what happens when
>you have >= 2G of available memory.
>
>If you want to check out manual pages for sysctl(3) for various *BSD
>systems, you can find them on http://www.freebsd.org/docs.html#man
>
>Krzysztof
>


>#include <stdio.h>
>#include <sys/types.h>
#include <sys/param.h>
>#include <sys/sysctl.h>
>
>int main() {
>    int mib[2];
>    int physmem, usermem, pagesize;
>    size_t len;
>
>    mib[0] = CTL_HW;
>
>    mib[1] = HW_PHYSMEM;
>    len = sizeof(int);
>    if (sysctl(mib, 2, &physmem, &len, NULL, 0) != 0) perror("sysctl");
>
>    mib[1] = HW_USERMEM;
>    len = sizeof(int);
>    if (sysctl(mib, 2, &usermem, &len, NULL, 0) != 0) perror("sysctl");
>
>    mib[1] = HW_PAGESIZE;
>    len = sizeof(int);
>    if (sysctl(mib, 2, &pagesize, &len, NULL, 0) != 0) perror("sysctl");
>
>    printf("physmem = %d bytes\nusermem = %d bytes\npagesize = %d bytes\n",
>        physmem, usermem, pagesize);
>
>}
>
>


And it's good on OpenBSD as well (and almost certainly NetBSD)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]