2012-09-02 51 views
0

下面調用SetSystemFileCacheSize()失敗,但它傳遞如果與0電話SetSystemFileCacheSize未能在C++

取代「FILE_CACHE_MIN_HARD_ENABLE」我在做什麼錯?

SIZE_T dwMinimumFileCacheSize = 1048576; // Exact number reported by SetSystemFileCacheSize. 
SIZE_T dwMaximumFileCacheSize = 1099511627776; // Exact number reported by SetSystemFileCacheSize. 

int result = SetSystemFileCacheSize(
    dwMinimumFileCacheSize, // dwMinimumWorkingSetSize 
    dwMaximumFileCacheSize, // dwMaximumWorkingSetSize, 
    FILE_CACHE_MIN_HARD_ENABLE // Works if this flag is set to 0. 
); 
if (result == 0) 
{ 
    // Error is "5" if it fails. 
    wprintf(L" Error E2469: Could not set size of system cache, error %u.\n", GetLastError()); 
} 
else 
{ 
    wprintf(L" Pass.\n"); 
} 
+1

是否啓用了SE_INCREASE_QUOTA_NAME特權? –

+0

@Alan Stokes好主意,我馬上試試。 – Contango

+1

錯誤'5' ='ERROR_ACCESS_DENIED'應該提示您缺少權限。 –

回答

0

事實證明,dwMinimumFileCacheSize必須比dwMaximumFileCacheSize少64KB,如果啓用FILE_CACHE_MIN_HARD_ENABLE。

這裏是修復:

int result = SetSystemFileCacheSize(
    dwMinimumFileCacheSize - 64 * 1024, // dwMinimumWorkingSetSize 
    dwMaximumFileCacheSize, // dwMaximumWorkingSetSize, 
    FILE_CACHE_MIN_HARD_ENABLE // Works if this flag is set to 0. 
);