--- src/os_win32.c	2008-08-23 19:43:54.265625000 +0200
+++ src/os_win32.c.patched	2008-08-23 19:43:36.296875000 +0200
@@ -4274,17 +4274,50 @@
 
 /*
  * How much memory is available?
- * Return sum of available physical and page file memory.
+ * Return sum of available physical and page file memory on success, non-zero
+ * for failure.
+ *
+ * ============================================================================
+ * Use GlobalMemoryStatusEx instead of GlobalMemoryStatus on systems were we
+ * can, since it's more reliable.
+ *
+ * Sometimes adding availPhys + availPageFile caused an overflow on 32-bit
+ * systems, so that's why I added a check to see if it would overflow. In those
+ * cases, 0xffffff00 is returned to indicate there is plenty of memory
+ * available, but we can't tell how much since we return a 32-bit integer on
+ * some platforms.
+ * We can't just "if (availPhys + availPageFile >= 0xffffff00)" so that's why I
+ * did "if (availPageFile >= (0xffffff00 - availPhys))".
+ *
+ * -- Jelle Geerts, 20080823
+ * ============================================================================
  */
 /*ARGSUSED*/
     long_u
 mch_avail_mem(int special)
 {
+#if (_WIN32_WINNT >= 0x0500)
+    // If we're on NT >= 0x0500, we will use GlobalMemoryStatusEx, which is
+    // more reliable on systems with >4 GiB of memory.
+    MEMORYSTATUSEX	msex;
+
+    msex.dwLength = sizeof(MEMORYSTATUSEX);
+    if (!GlobalMemoryStatusEx(&msex))
+        return -1;
+# ifndef _WIN64
+    if (ms.dwAvailPageFile >= (0xffffff00 - ms.dwAvailPhys))
+        return 0xffffff00;
+# endif
+    return msex.ullAvailPhys + msex.ullAvailPageFile;
+#else
     MEMORYSTATUS	ms;
 
     ms.dwLength = sizeof(MEMORYSTATUS);
     GlobalMemoryStatus(&ms);
+    if (ms.dwAvailPageFile >= (0xffffff00 - ms.dwAvailPhys))
+        return 0xffffff00;
     return (long_u) (ms.dwAvailPhys + ms.dwAvailPageFile);
+#endif
 }
 
 #ifdef FEAT_MBYTE
