Bug 44352. Adding IsLowMemory predicate & implementation for Windows.
git-svn-id: svn://10.0.0.236/trunk@77069 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
bc10558244
commit
61661b6160
@ -98,6 +98,13 @@ interface nsIMemory : nsISupports
|
||||
* @param obs - the observer to unregister
|
||||
*/
|
||||
void unregisterObserver(in nsIMemoryPressureObserver obs);
|
||||
|
||||
/**
|
||||
* This predicate can be used to determine if we're in a low-memory
|
||||
* situation (what constitutes low-memory is platform dependent). This
|
||||
* can be used to trigger the memory flushers.
|
||||
*/
|
||||
boolean isLowMemory();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -24,6 +24,10 @@
|
||||
#include "prmem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMemoryImpl, nsIMemory)
|
||||
|
||||
NS_METHOD
|
||||
@ -46,7 +50,7 @@ nsMemoryImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Define NS_OUT_OF_MEMORY_TESTER if you want to force memory failures
|
||||
|
||||
#ifdef DEBUG_warren
|
||||
#ifdef DEBUG_xwarren
|
||||
#define NS_OUT_OF_MEMORY_TESTER
|
||||
#endif
|
||||
|
||||
@ -164,6 +168,20 @@ nsMemoryImpl::UnregisterObserver(nsIMemoryPressureObserver* obs)
|
||||
return mObservers->RemoveElement(obs);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryImpl::IsLowMemory(PRBool *result)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
MEMORYSTATUS stat;
|
||||
GlobalMemoryStatus(&stat);
|
||||
*result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;
|
||||
return NS_OK;
|
||||
#else
|
||||
NS_NOTREACHED("nsMemoryImpl::IsLowMemory");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMemoryImpl::FlushMemory(PRUint32 reason, PRSize size)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user