Skip to content

Commit ee27397

Browse files
committed
patch 7.4.1033
Problem: Memory use on MS-Windows is very conservative. Solution: Use the global memory status to estimate amount of memory. (Mike Williams)
1 parent cbfe329 commit ee27397

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

src/os_win32.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/*

src/os_win32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
# define BREAKCHECK_SKIP 1 /* call mch_breakcheck() each time, it's fast */
7979
#endif
8080

81+
#define HAVE_TOTAL_MEM
82+
8183
#define HAVE_PUTENV /* at least Bcc 5.2 and MSC have it */
8284

8385
#ifdef FEAT_GUI_W32

src/proto/os_win32.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void mch_write __ARGS((char_u *s, int len));
4343
void mch_delay __ARGS((long msec, int ignoreinput));
4444
int mch_remove __ARGS((char_u *name));
4545
void mch_breakcheck __ARGS((void));
46+
long_u mch_total_mem __ARGS((int special));
4647
int mch_wrename __ARGS((WCHAR *wold, WCHAR *wnew));
4748
int mch_rename __ARGS((const char *pszOldFile, const char *pszNewFile));
4849
char *default_shell __ARGS((void));

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1033,
744746
/**/
745747
1032,
746748
/**/

0 commit comments

Comments
 (0)