Share via


C6331

경고 C6331: 매개 변수가 잘못되었습니다. <function>과(와) 함께 MEM_RELEASE 및 MEM_DECOMMIT를 전달하면 호출이 실패합니다.

이 메시지는 VirtualFree 또는 VirtualFreeEx에 잘못된 매개 변수가 전달되고 있다는 것을 나타냅니다. VirtualFree 및 VirtualFreeEx는 플래그(MEM_RELEASE | MEM_DECOMMIT)와의 조합을 거부합니다. 따라서 MEM_DECOMMIT 및 MEM_RELEASE 값을 같은 호출에 함께 사용할 수 없습니다.

decommit과 해제를 독립된 단계로 수행할 필요는 없습니다. 커밋된 메모리를 해제하면 페이지도 decommit됩니다. 또한 이 함수의 반환 값이 무시되지 않도록 해야 합니다.

예제

다음 샘플 코드에서는 이 경고를 발생시킵니다.

#include <windows.h>
#define PAGELIMIT 80

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

VOID fd( 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_DECOMMIT | MEM_RELEASE); // warning 
  // code...
}

이 경고를 해결하려면 다음 코드에서처럼 MEM_DECOMMIT 값을 VirtualFree 호출에 전달하지 않도록 합니다.

#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); 
  // code...
}

참고 항목

참조

IHostMemoryManager::VirtualAlloc 메서드

IHostMemoryManager::VirtualFree 메서드