C6333

警告 C6333: 無效的參數: 不允許傳遞 MEM_RELEASE 和非零的 dwSize 參數至 <function>。 這樣就會造成這個呼叫的失敗

這則警告表示無效的參數將會傳遞至 VirtualFree 或 VirtualFreeEx。 這兩個函式都會拒絕其 dwSize 為非零值之 MEM_RELEASE 的 dwFreeType。 傳遞 MEM_RELEASE 時,dwSize 參數必須為零。 同時,請確定未忽略此函式的傳回值。

範例

下列範例程式碼會產生這則警告:

#include <windows.h>
#define PAGELIMIT 80            

DWORD dwPages = 0;  // count of pages 
DWORD dwPageSize;   // page size 

VOID f( VOID )
{
  LPVOID lpvBase;            // base address of the test memory
  BOOL bSuccess;           
  SYSTEM_INFO sSysInfo;      // system information

  GetSystemInfo( &sSysInfo );  
  dwPageSize = sSysInfo.dwPageSize;

  // Reserve pages in the process's virtual address space
  lpvBase = VirtualAlloc(
                         NULL,                // system selects address
                         PAGELIMIT*dwPageSize,// size of allocation
                         MEM_RESERVE,        
                         PAGE_NOACCESS );     
  if (lpvBase)
  {
    // code to access memory 
  }
  else
  {
    return;
  }

  bSuccess = VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_RELEASE); 
  //code...
}

若要更正這則警告,請使用下列範例程式碼:

#include <windows.h>
#define PAGELIMIT 80            

DWORD dwPages = 0;  // count of pages 
DWORD dwPageSize;   // page size 

VOID f( VOID )
{
  LPVOID lpvBase;            // base address of the test memory
  BOOL bSuccess;           
  SYSTEM_INFO sSysInfo;      // system information

  GetSystemInfo( &sSysInfo );  
  dwPageSize = sSysInfo.dwPageSize;

  // Reserve pages in the process's virtual address space
  lpvBase = VirtualAlloc(
                         NULL,                // system selects address
                         PAGELIMIT*dwPageSize,// size of allocation
                         MEM_RESERVE,        
                         PAGE_NOACCESS );     
  if (lpvBase)
  {
    // code to access memory 
  }
  else
  {
    return;
  }
  bSuccess = VirtualFree(lpvBase, 0, MEM_RELEASE );

  //  VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT); 
  // code...
}

您也可以使用 VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT); 呼叫以解除分頁,稍後再使用 MEM_RELEASE 旗標加以釋放。

請參閱

參考

IHostMemoryManager::VirtualAlloc 方法

IHostMemoryManager::VirtualFree 方法