Skip to content
Snippets Groups Projects
Commit 6189c198 authored by Marcus Meissner's avatar Marcus Meissner Committed by Alexandre Julliard
Browse files

Some applications call GlobalMemoryStatus() very often. Cache the

results of the call for 1 second (spotted by Corel).
parent 9b84bb66
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
...@@ -1458,8 +1459,18 @@ DWORD WINAPI GlobalCompact( DWORD minfree ) ...@@ -1458,8 +1459,18 @@ DWORD WINAPI GlobalCompact( DWORD minfree )
VOID WINAPI GlobalMemoryStatus( VOID WINAPI GlobalMemoryStatus(
LPMEMORYSTATUS lpmem 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 #ifdef linux
FILE *f = fopen( "/proc/meminfo", "r" ); f = fopen( "/proc/meminfo", "r" );
if (f) if (f)
{ {
char buffer[256]; char buffer[256];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment