map file最小粒度可以通过
void GetSystemInfo(
LPSYSTEM_INFO lpSystemInfo
);
lpSystemInfo->dwPageSize
得到;基本上都是4K。那么,进行FileMapping的时候,只要分配的小于4K,系统都会按照4K来进行;例子为证:
void CMapViewDlg::OnCancel2()
{
long lPageSize(10);
AllocFileMapping(lPageSize);
}
const int MAP_SIZE = 7;
void CMapViewDlg::AllocFileMapping(int lPageSize)
{
HANDLE hMap[MAP_SIZE];
LPVOID lpMapView[MAP_SIZE];
for ( int n = 0; n < MAP_SIZE; n++ )
{
// Create a new page with appointed page name and length
CString csPage;
csPage.Format(_T("Page%d"), n);
hMap[n] = ::CreateFileMapping( INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
lPageSize,
csPage );
// MapView and save page info to
lpMapView[n] = ::MapViewOfFile( hMap[n],
FILE_MAP_ALL_ACCESS,
0,
0,
0 );
memset(lpMapView[n], n, lPageSize);
}
for ( n = 0; n < MAP_SIZE; n++ )
{
::UnmapViewOfFile( lpMapView[n] );
::CloseHandle( hMap[n] );
hMap[n] = NULL;
}
}
结果是7*4K。