Mercurial > hg > octave-kai > gnulib-hg
annotate lib/physmem.c @ 17342:c75939cb6254
merge with default branch
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 21 Feb 2013 14:57:31 +0000 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
3064 | 1 /* Calculate the size of physical memory. |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
2 |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
3 Copyright (C) 2000-2001, 2003, 2005-2006, 2009-2013 Free Software |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12518
diff
changeset
|
4 Foundation, Inc. |
3064 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
3064 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
9 (at your option) any later version. |
3064 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
3064 | 18 |
19 /* Written by Paul Eggert. */ | |
20 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
21 #include <config.h> |
3064 | 22 |
23 #include "physmem.h" | |
24 | |
6275 | 25 #include <unistd.h> |
3064 | 26 |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
27 #if HAVE_SYS_PSTAT_H |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
28 # include <sys/pstat.h> |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
29 #endif |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
30 |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
31 #if HAVE_SYS_SYSMP_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
32 # include <sys/sysmp.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
33 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
34 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
35 #if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
36 # include <sys/sysinfo.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
37 # include <machine/hal_sysinfo.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
38 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
39 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
40 #if HAVE_SYS_TABLE_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
41 # include <sys/table.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
42 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
43 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
44 #include <sys/types.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
45 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
46 #if HAVE_SYS_PARAM_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
47 # include <sys/param.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
48 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
49 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
50 #if HAVE_SYS_SYSCTL_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
51 # include <sys/sysctl.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
52 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
53 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
54 #if HAVE_SYS_SYSTEMCFG_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
55 # include <sys/systemcfg.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
56 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
57 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
58 #ifdef _WIN32 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
59 # define WIN32_LEAN_AND_MEAN |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
60 # include <windows.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
61 /* MEMORYSTATUSEX is missing from older windows headers, so define |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
62 a local replacement. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
63 typedef struct |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
64 { |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
65 DWORD dwLength; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
66 DWORD dwMemoryLoad; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
67 DWORDLONG ullTotalPhys; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
68 DWORDLONG ullAvailPhys; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
69 DWORDLONG ullTotalPageFile; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
70 DWORDLONG ullAvailPageFile; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
71 DWORDLONG ullTotalVirtual; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
72 DWORDLONG ullAvailVirtual; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
73 DWORDLONG ullAvailExtendedVirtual; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
74 } lMEMORYSTATUSEX; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
75 typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
76 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
77 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
78 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
79 |
3064 | 80 /* Return the total amount of physical memory. */ |
81 double | |
4669
c7ad68a45173
(physmem_total, physmem_available, main): Define with prototypes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4551
diff
changeset
|
82 physmem_total (void) |
3064 | 83 { |
84 #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
85 { /* This works on linux-gnu, solaris2 and cygwin. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
86 double pages = sysconf (_SC_PHYS_PAGES); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
87 double pagesize = sysconf (_SC_PAGESIZE); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
88 if (0 <= pages && 0 <= pagesize) |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
89 return pages * pagesize; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
90 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
91 #endif |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
92 |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
93 #if HAVE_PSTAT_GETSTATIC |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
94 { /* This works on hpux11. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
95 struct pst_static pss; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
96 if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)) |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
97 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
98 double pages = pss.physical_memory; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
99 double pagesize = pss.page_size; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
100 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
101 return pages * pagesize; |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
102 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
103 } |
3064 | 104 #endif |
105 | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
106 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
107 { /* This works on irix6. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
108 struct rminfo realmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
109 if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
110 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
111 double pagesize = sysconf (_SC_PAGESIZE); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
112 double pages = realmem.physmem; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
113 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
114 return pages * pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
115 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
116 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
117 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
118 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
119 #if HAVE_GETSYSINFO && defined GSI_PHYSMEM |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
120 { /* This works on Tru64 UNIX V4/5. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
121 int physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
122 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
123 if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
124 NULL, NULL, NULL) == 1) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
125 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
126 double kbytes = physmem; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
127 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
128 if (0 <= kbytes) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
129 return kbytes * 1024.0; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
130 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
131 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
132 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
133 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
134 #if HAVE_SYSCTL && defined HW_PHYSMEM |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
135 { /* This works on *bsd and darwin. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
136 unsigned int physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
137 size_t len = sizeof physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
138 static int mib[2] = { CTL_HW, HW_PHYSMEM }; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
139 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
140 if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
141 && len == sizeof (physmem)) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
142 return (double) physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
143 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
144 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
145 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
146 #if HAVE__SYSTEM_CONFIGURATION |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
147 /* This works on AIX. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
148 return _system_configuration.physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
149 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
150 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
151 #if defined _WIN32 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
152 { /* this works on windows */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
153 PFN_MS_EX pfnex; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
154 HMODULE h = GetModuleHandle ("kernel32.dll"); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
155 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
156 if (!h) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
157 return 0.0; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
158 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
159 /* Use GlobalMemoryStatusEx if available. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
160 if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
161 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
162 lMEMORYSTATUSEX lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
163 lms_ex.dwLength = sizeof lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
164 if (!pfnex (&lms_ex)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
165 return 0.0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
166 return (double) lms_ex.ullTotalPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
167 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
168 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
169 /* Fall back to GlobalMemoryStatus which is always available. |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
170 but returns wrong results for physical memory > 4GB. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
171 else |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
172 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
173 MEMORYSTATUS ms; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
174 GlobalMemoryStatus (&ms); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
175 return (double) ms.dwTotalPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
176 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
177 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
178 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
179 |
3064 | 180 /* Guess 64 MB. It's probably an older host, so guess small. */ |
181 return 64 * 1024 * 1024; | |
182 } | |
183 | |
184 /* Return the amount of physical memory available. */ | |
185 double | |
4669
c7ad68a45173
(physmem_total, physmem_available, main): Define with prototypes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4551
diff
changeset
|
186 physmem_available (void) |
3064 | 187 { |
188 #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
189 { /* This works on linux-gnu, solaris2 and cygwin. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
190 double pages = sysconf (_SC_AVPHYS_PAGES); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
191 double pagesize = sysconf (_SC_PAGESIZE); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
192 if (0 <= pages && 0 <= pagesize) |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
193 return pages * pagesize; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
194 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
195 #endif |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
196 |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
197 #if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
198 { /* This works on hpux11. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
199 struct pst_static pss; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
200 struct pst_dynamic psd; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
201 if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
202 && 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0)) |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
203 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
204 double pages = psd.psd_free; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
205 double pagesize = pss.page_size; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
206 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
207 return pages * pagesize; |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
208 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
209 } |
3064 | 210 #endif |
211 | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
212 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
213 { /* This works on irix6. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
214 struct rminfo realmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
215 if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
216 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
217 double pagesize = sysconf (_SC_PAGESIZE); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
218 double pages = realmem.availrmem; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
219 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
220 return pages * pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
221 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
222 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
223 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
224 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
225 #if HAVE_TABLE && defined TBL_VMSTATS |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
226 { /* This works on Tru64 UNIX V4/5. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
227 struct tbl_vmstats vmstats; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
228 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
229 if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
230 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
231 double pages = vmstats.free_count; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
232 double pagesize = vmstats.pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
233 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
234 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
235 return pages * pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
236 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
237 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
238 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
239 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
240 #if HAVE_SYSCTL && defined HW_USERMEM |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
241 { /* This works on *bsd and darwin. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
242 unsigned int usermem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
243 size_t len = sizeof usermem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
244 static int mib[2] = { CTL_HW, HW_USERMEM }; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
245 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
246 if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
247 && len == sizeof (usermem)) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
248 return (double) usermem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
249 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
250 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
251 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
252 #if defined _WIN32 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
253 { /* this works on windows */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
254 PFN_MS_EX pfnex; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
255 HMODULE h = GetModuleHandle ("kernel32.dll"); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
256 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
257 if (!h) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
258 return 0.0; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
259 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
260 /* Use GlobalMemoryStatusEx if available. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
261 if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
262 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
263 lMEMORYSTATUSEX lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
264 lms_ex.dwLength = sizeof lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
265 if (!pfnex (&lms_ex)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
266 return 0.0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
267 return (double) lms_ex.ullAvailPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
268 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
269 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
270 /* Fall back to GlobalMemoryStatus which is always available. |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
271 but returns wrong results for physical memory > 4GB */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
272 else |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
273 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
274 MEMORYSTATUS ms; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
275 GlobalMemoryStatus (&ms); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
276 return (double) ms.dwAvailPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
277 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
278 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
279 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
280 |
3064 | 281 /* Guess 25% of physical memory. */ |
282 return physmem_total () / 4; | |
283 } | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
284 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
285 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
286 #if DEBUG |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
287 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
288 # include <stdio.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
289 # include <stdlib.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
290 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
291 int |
4669
c7ad68a45173
(physmem_total, physmem_available, main): Define with prototypes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4551
diff
changeset
|
292 main (void) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
293 { |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
294 printf ("%12.f %12.f\n", physmem_total (), physmem_available ()); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
295 exit (0); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
296 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
297 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
298 #endif /* DEBUG */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
299 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
300 /* |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
301 Local Variables: |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
302 compile-command: "gcc -DDEBUG -g -O -Wall -W physmem.c" |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
303 End: |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
304 */ |