From 6189c198ecd9fd37d995ebc886b7096adb81b0d1 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Sat, 4 Mar 2000 19:19:15 +0000 Subject: [PATCH] Some applications call GlobalMemoryStatus() very often. Cache the results of the call for 1 second (spotted by Corel). --- memory/global.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/memory/global.c b/memory/global.c index 5cecdf4647e..302a7e11884 100644 --- a/memory/global.c +++ b/memory/global.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -1458,8 +1459,18 @@ DWORD WINAPI GlobalCompact( DWORD minfree ) VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpmem ) { + static MEMORYSTATUS cached_memstatus; + static int cache_lastchecked = 0; + FILE *f; + + if (time(NULL)==cache_lastchecked) { + memcpy(lpmem,&cached_memstatus,sizeof(MEMORYSTATUS)); + return; + } + cache_lastchecked = time(NULL); + #ifdef linux - FILE *f = fopen( "/proc/meminfo", "r" ); + f = fopen( "/proc/meminfo", "r" ); if (f) { char buffer[256];