summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/alloc.c16
-rw-r--r--src/w32.c29
-rw-r--r--src/w32.h4
4 files changed, 53 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 87a8f1c7814..93ad0ded350 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2014-07-10 Eli Zaretskii <eliz@gnu.org>
+
+ Implement memory-info for MS-Windows.
+ * w32.c (w32_memory_info): New function.
+ * w32.h (w32_memory_info): Prototype it.
+ * alloc.c (Fmemory_info) [WINDOWSNT]: Call it.
+
2014-07-10 Dmitry Antipov <dmantipov@yandex.ru>
* coding.h (struct coding_system): Remove 'error_positions' (unused)
diff --git a/src/alloc.c b/src/alloc.c
index c535e836397..4a912703c39 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6875,7 +6875,7 @@ All values are in Kbytes. If there is no swap space, last two
values are zero. If the system is not supported, return nil. */)
(void)
{
-#ifdef HAVE_LINUX_SYSINFO
+#if defined HAVE_LINUX_SYSINFO
struct sysinfo si;
uintmax_t units;
@@ -6885,12 +6885,22 @@ values are zero. If the system is not supported, return nil. */)
units = si.mem_unit;
#else
units = 1;
-#endif
+#endif
return list4i ((uintmax_t) si.totalram * units / 1024,
(uintmax_t) si.freeram * units / 1024,
(uintmax_t) si.totalswap * units / 1024,
(uintmax_t) si.freeswap * units / 1024);
-#else /* not HAVE_LINUX_SYSINFO */
+#elif defined WINDOWSNT
+ unsigned long long totalram, freeram, totalswap, freeswap;
+
+ if (w32_memory_info (&totalram, &freeram, &totalswap, &freeswap) == 0)
+ return list4i ((uintmax_t) totalram / 1024,
+ (uintmax_t) freeram / 1024,
+ (uintmax_t) totalswap / 1024,
+ (uintmax_t) freeswap / 1024);
+ else
+ return Qnil;
+#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT */
/* FIXME: add more systems. */
return Qnil;
#endif /* HAVE_LINUX_SYSINFO */
diff --git a/src/w32.c b/src/w32.c
index c5d4aa0fe8e..37a01a311a6 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -6955,6 +6955,35 @@ system_process_attributes (Lisp_Object pid)
return attrs;
}
+int
+w32_memory_info (unsigned long long *totalram, unsigned long long *freeram,
+ unsigned long long *totalswap, unsigned long long *freeswap)
+{
+ MEMORYSTATUS memst;
+ MEMORY_STATUS_EX memstex;
+
+ /* Use GlobalMemoryStatusEx if available, as it can report more than
+ 2GB of memory. */
+ if (global_memory_status_ex (&memstex))
+ {
+ *totalram = memstex.ullTotalPhys;
+ *freeram = memstex.ullAvailPhys;
+ *totalswap = memstex.ullTotalPageFile;
+ *freeswap = memstex.ullAvailPageFile;
+ return 0;
+ }
+ else if (global_memory_status (&memst))
+ {
+ *totalram = memst.dwTotalPhys;
+ *freeram = memst.dwAvailPhys;
+ *totalswap = memst.dwTotalPageFile;
+ *freeswap = memst.dwAvailPageFile;
+ return 0;
+ }
+ else
+ return -1;
+}
+
/* Wrappers for winsock functions to map between our file descriptors
and winsock's handles; also set h_errno for convenience.
diff --git a/src/w32.h b/src/w32.h
index 33fd2709a71..94f7a962833 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -206,6 +206,10 @@ extern void register_child (pid_t, int);
extern void sys_sleep (int);
extern int sys_link (const char *, const char *);
+/* Return total and free memory info. */
+extern int w32_memory_info (unsigned long long *, unsigned long long *,
+ unsigned long long *, unsigned long long *);
+
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>