Hiya

On 18/12/2015 09:15, Ken Takata wrote:
Hi Mike,

2015/12/18 Fri 17:45:27 UTC+9 Mike Williams wrote:
Attached is a patch that sets the maxmem options at startup on Windows
OSes based on reported memory availability.  It uses a simple heuristic
to derive a value to use.  The checks for limited memory systems from
the dark ages of last century may not be ideal, if anyone is still
nursing such a system it would be nice to try the patch on it to see if
the reserve numbers need to be tweaked.

I think we can drop support for win9x. But (if needed) we can still

Bram - any comment on finally dropping 95 support? As in Win32s (ah, happy days) - I can no longer do builds or run them so cannot check the effect.

use GlobalMemoryStatus() just for old compilers like this:

#ifdef MEMORYSTATUSEX
  /* Use GlobalMemoryStatusEx() for recent compilers */
#else
  /* Use GlobalMemoryStatus() for old compilers */
#endif

Win2K does not support GlobalMemoryStatusEx(). The default Windows build sets WINVER to 0x0400 to support Win2K compatible builds and this excludes MEMORYSTATUSEX, so it is not new/compilers but old/new versions of NT.

Attached is an updated patch to fix the memory values for NT in default builds, and avoid a possible return of 0 bytes available!

TTFN

Mike
--
Anger is never without reason, but seldom with a good one.

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/os_win32.c b/src/os_win32.c
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -5858,6 +5858,66 @@ mch_breakcheck(void)
 #endif
 }
 
+/* Physical RAM to leave for the OS */
+#define WINNT_RESERVE_BYTES     (256*1024*1024)
+#define WIN95_RESERVE_BYTES     (8*1024*1024)
+
+/*
+ * How much main memory in KiB that can be used by VIM.
+ */
+/*ARGSUSED*/
+    long_u
+mch_total_mem(int special)
+{
+    PlatformId();
+#ifdef MEMORYSTATUSEX
+    if (g_PlatformId == VER_PLATFORM_WIN32_NT)
+    {
+        MEMORYSTATUSEX  ms;
+
+        /* Need to use GlobalMemoryStatusEx() when there is more memory than
+         * what fits in 32 bits. But it's not always available. */
+        ms.dwLength = sizeof(MEMORYSTATUSEX);
+        GlobalMemoryStatusEx(&ms);
+        if (ms.ullAvailVirtual < ms.ullTotalPhys)
+        {
+            /* Process address space fits in physical RAM, use all of it */
+            return (long_u)(ms.ullAvailVirtual/1024);
+        }
+        if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES)
+        {
+            /* Catch old NT box or perverse hardware setup */
+            return (long_u)((ms.ullTotalPhys/2)/1024);
+        }
+        /* Use physical RAM less reserve for OS + data */
+        return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES)/1024);
+    }
+    else
+#endif
+    {
+        /* Pre-XP or 95 OS handling */
+        MEMORYSTATUS    ms;
+        long_u os_reserve_bytes;
+
+        ms.dwLength = sizeof(MEMORYSTATUS);
+        GlobalMemoryStatus(&ms);
+        if (ms.dwAvailVirtual < ms.dwTotalPhys)
+        {
+            /* Process address space fits in physical RAM, use all of it */
+            return (long_u)(ms.dwAvailVirtual/1024);
+        }
+        os_reserve_bytes = (g_PlatformId == VER_PLATFORM_WIN32_NT)
+            ? WINNT_RESERVE_BYTES
+            : WIN95_RESERVE_BYTES;
+        if (ms.dwTotalPhys <= os_reserve_bytes)
+        {
+            /* Catch old boxes or perverse hardware setup */
+            return (long_u)((ms.dwTotalPhys/2)/1024);
+        }
+        /* Use physical RAM less reserve for OS + data */
+        return (long_u)((ms.dwTotalPhys - os_reserve_bytes)/1024);
+    }
+}
 
 #ifdef FEAT_MBYTE
 /*
diff --git a/src/os_win32.h b/src/os_win32.h
--- a/src/os_win32.h
+++ b/src/os_win32.h
@@ -78,6 +78,8 @@
 # define BREAKCHECK_SKIP    1	/* call mch_breakcheck() each time, it's fast */
 #endif
 
+#define HAVE_TOTAL_MEM
+
 #define HAVE_PUTENV		/* at least Bcc 5.2 and MSC have it */
 
 #ifdef FEAT_GUI_W32
diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro
--- a/src/proto/os_win32.pro
+++ b/src/proto/os_win32.pro
@@ -43,6 +43,7 @@ void mch_write __ARGS((char_u *s, int le
 void mch_delay __ARGS((long msec, int ignoreinput));
 int mch_remove __ARGS((char_u *name));
 void mch_breakcheck __ARGS((void));
+long_u mch_total_mem __ARGS((int special));
 int mch_wrename __ARGS((WCHAR *wold, WCHAR *wnew));
 int mch_rename __ARGS((const char *pszOldFile, const char *pszNewFile));
 char *default_shell __ARGS((void));

Raspunde prin e-mail lui