@@ -5858,6 +5858,66 @@ mch_breakcheck(void)
58585858#endif
58595859}
58605860
5861+ /* physical RAM to leave for the OS */
5862+ #define WINNT_RESERVE_BYTES (256*1024*1024)
5863+ #define WIN95_RESERVE_BYTES (8*1024*1024)
5864+
5865+ /*
5866+ * How much main memory in KiB that can be used by VIM.
5867+ */
5868+ /*ARGSUSED*/
5869+ long_u
5870+ mch_total_mem (int special )
5871+ {
5872+ PlatformId ();
5873+ #if (defined(_MSC_VER ) && (WINVER > 0x0400 )) || defined(MEMORYSTATUSEX )
5874+ if (g_PlatformId == VER_PLATFORM_WIN32_NT )
5875+ {
5876+ MEMORYSTATUSEX ms ;
5877+
5878+ /* Need to use GlobalMemoryStatusEx() when there is more memory than
5879+ * what fits in 32 bits. But it's not always available. */
5880+ ms .dwLength = sizeof (MEMORYSTATUSEX );
5881+ GlobalMemoryStatusEx (& ms );
5882+ if (ms .ullAvailVirtual < ms .ullTotalPhys )
5883+ {
5884+ /* Process address space fits in physical RAM, use all of it. */
5885+ return (long_u )(ms .ullAvailVirtual / 1024 );
5886+ }
5887+ if (ms .ullTotalPhys <= WINNT_RESERVE_BYTES )
5888+ {
5889+ /* Catch old NT box or perverse hardware setup. */
5890+ return (long_u )((ms .ullTotalPhys / 2 ) / 1024 );
5891+ }
5892+ /* Use physical RAM less reserve for OS + data. */
5893+ return (long_u )((ms .ullTotalPhys - WINNT_RESERVE_BYTES ) / 1024 );
5894+ }
5895+ else
5896+ #endif
5897+ {
5898+ /* Pre-XP or 95 OS handling. */
5899+ MEMORYSTATUS ms ;
5900+ long_u os_reserve_bytes ;
5901+
5902+ ms .dwLength = sizeof (MEMORYSTATUS );
5903+ GlobalMemoryStatus (& ms );
5904+ if (ms .dwAvailVirtual < ms .dwTotalPhys )
5905+ {
5906+ /* Process address space fits in physical RAM, use all of it. */
5907+ return (long_u )(ms .dwAvailVirtual / 1024 );
5908+ }
5909+ os_reserve_bytes = (g_PlatformId == VER_PLATFORM_WIN32_NT )
5910+ ? WINNT_RESERVE_BYTES
5911+ : WIN95_RESERVE_BYTES ;
5912+ if (ms .dwTotalPhys <= os_reserve_bytes )
5913+ {
5914+ /* Catch old boxes or perverse hardware setup. */
5915+ return (long_u )((ms .dwTotalPhys / 2 ) / 1024 );
5916+ }
5917+ /* Use physical RAM less reserve for OS + data. */
5918+ return (long_u )((ms .dwTotalPhys - os_reserve_bytes ) / 1024 );
5919+ }
5920+ }
58615921
58625922#ifdef FEAT_MBYTE
58635923/*
0 commit comments