C6333

警告 C6333:无效的参数: 不允许将 MEM_RELEASE 和非零 dwSize 参数一起传递给 <function>。这会导致此调用失败

此警告意味着向 VirtualFree 或 VirtualFreeEx 传递的参数无效。当 dwSize 的值不为 0 时,上述两个函数都将拒绝 MEM_RELEASE 的 dwFreeType。当传递 MEM_RELEASE 时,dwSize 参数必须为 0。此外,请确保未忽略此函数的返回值。

示例

下面的代码示例生成此警告:

#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 方法