emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117510: Implement memory-info for MS-Windows.


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r117510: Implement memory-info for MS-Windows.
Date: Thu, 10 Jul 2014 19:09:49 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117510
revision-id: address@hidden
parent: address@hidden
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Thu 2014-07-10 22:09:26 +0300
message:
  Implement memory-info for MS-Windows.
  
   src/w32.c (w32_memory_info): New function.
   src/w32.h (w32_memory_info): Prototype it.
   src/alloc.c (Fmemory_info) [WINDOWSNT]: Call it.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/alloc.c                    alloc.c-20091113204419-o5vbwnq5f7feedwu-252
  src/w32.c                      w32.c-20091113204419-o5vbwnq5f7feedwu-808
  src/w32.h                      w32.h-20091113204419-o5vbwnq5f7feedwu-809
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-07-10 12:33:35 +0000
+++ b/src/ChangeLog     2014-07-10 19:09:26 +0000
@@ -1,3 +1,10 @@
+2014-07-10  Eli Zaretskii  <address@hidden>
+
+       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  <address@hidden>
 
        * coding.h (struct coding_system): Remove 'error_positions' (unused)

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2014-07-10 12:33:35 +0000
+++ b/src/alloc.c       2014-07-10 19:09:26 +0000
@@ -6875,7 +6875,7 @@
 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 @@
   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 */

=== modified file 'src/w32.c'
--- a/src/w32.c 2014-07-09 02:04:12 +0000
+++ b/src/w32.c 2014-07-10 19:09:26 +0000
@@ -6955,6 +6955,35 @@
   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.

=== modified file 'src/w32.h'
--- a/src/w32.h 2014-02-06 15:27:46 +0000
+++ b/src/w32.h 2014-07-10 19:09:26 +0000
@@ -206,6 +206,10 @@
 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>
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]