about Operator of >> and << in the Memory-Mapping Files.
-
Hello,i study the windows via c/c++.but i have some problems about this routine. //Wiews must always start on a multiple of the allocation granularity SYSTEM_INFO sinf; GetSystemInfo(&sinf); //Open the data file. HANDLE hFile = CreateFile(TEXT("C:\\HugeFile.Big"), GENERIC_READ, FILE_SHARE_READ\ , NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); //Create the file-mapping object. HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); DWORD dwFileSizeHigh; _int64 qwFileSize = GetFileSize(hFile, &dwFileSizeHigh); qwFileSize += (((_int64)dwFileSizeHigh) << 32); //we no longer need access to the file object's handle. CloseHandle(hFile); _int64 qwFileOffset = 0, qwNumOfos = 0; while(qwFileSize > 0) { //Determine the number of bytes to be mapped in this view DWORD dwBytesInBlock = sinf.dwAllocationGranularity; if(qwFileSize < sinf.dwAllocationGranularity) dwBytesInBlock = (DWORD)qwFileSize; PBYTE pbFile = (PBYTE)MapViewOfFile(hFileMapping, FILE_MAP_READ, (DWORD)(qwFileOffset >> 32), (DWORD)(qwFileOffset & 0xFFFFFFFF), dwBytesInBlock); //Count the number of 0s in the block. for(DWORD dwByte = 0; dwByte < dwBytesInBlock; dwByte++) { if(pbFile[dwByte] == 0) qwNumOfos++; } //Unmap the view; we don't want multiple views in our address space. UnmapViewOfFile(pbFile); //Skip to the next set of bytes in the file. qwFileOffset += dwBytesInBlock; qwFileSize -= dwBytesInBlock; } CloseHandle(hFileMapping); i can't understand the qwFileSize += (((_int64)dwFileSizeHigh) << 32); and (DWORD)(qwFileOffset >> 32), (DWORD)(qwFileOffset & 0xFFFFFFFF) can you tell me something? thank you.
-
Hello,i study the windows via c/c++.but i have some problems about this routine. //Wiews must always start on a multiple of the allocation granularity SYSTEM_INFO sinf; GetSystemInfo(&sinf); //Open the data file. HANDLE hFile = CreateFile(TEXT("C:\\HugeFile.Big"), GENERIC_READ, FILE_SHARE_READ\ , NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); //Create the file-mapping object. HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); DWORD dwFileSizeHigh; _int64 qwFileSize = GetFileSize(hFile, &dwFileSizeHigh); qwFileSize += (((_int64)dwFileSizeHigh) << 32); //we no longer need access to the file object's handle. CloseHandle(hFile); _int64 qwFileOffset = 0, qwNumOfos = 0; while(qwFileSize > 0) { //Determine the number of bytes to be mapped in this view DWORD dwBytesInBlock = sinf.dwAllocationGranularity; if(qwFileSize < sinf.dwAllocationGranularity) dwBytesInBlock = (DWORD)qwFileSize; PBYTE pbFile = (PBYTE)MapViewOfFile(hFileMapping, FILE_MAP_READ, (DWORD)(qwFileOffset >> 32), (DWORD)(qwFileOffset & 0xFFFFFFFF), dwBytesInBlock); //Count the number of 0s in the block. for(DWORD dwByte = 0; dwByte < dwBytesInBlock; dwByte++) { if(pbFile[dwByte] == 0) qwNumOfos++; } //Unmap the view; we don't want multiple views in our address space. UnmapViewOfFile(pbFile); //Skip to the next set of bytes in the file. qwFileOffset += dwBytesInBlock; qwFileSize -= dwBytesInBlock; } CloseHandle(hFileMapping); i can't understand the qwFileSize += (((_int64)dwFileSizeHigh) << 32); and (DWORD)(qwFileOffset >> 32), (DWORD)(qwFileOffset & 0xFFFFFFFF) can you tell me something? thank you.
See the description for GetFileSize()[^]. This code is taking the two result values and creating the 64-bit composite value, by shifting the high order bits 32-bits left, casting the result to an
_int64
and adding to the low order value._int64 qwFileSize = GetFileSize(hFile, &dwFileSizeHigh);
qwFileSize += (((_int64)dwFileSizeHigh) << 32);This code is extracting the two 32-bit halves of the value and passing them to the
MapViewOfFile()
function. In both cases the results need to be cast toDWORD
s to keep the compiler happy.PBYTE pbFile = (PBYTE)MapViewOfFile(hFileMapping, FILE_MAP_READ,
(DWORD)(qwFileOffset >> 32),
(DWORD)(qwFileOffset & 0xFFFFFFFF),
dwBytesInBlock);It's time for a new signature.
-
See the description for GetFileSize()[^]. This code is taking the two result values and creating the 64-bit composite value, by shifting the high order bits 32-bits left, casting the result to an
_int64
and adding to the low order value._int64 qwFileSize = GetFileSize(hFile, &dwFileSizeHigh);
qwFileSize += (((_int64)dwFileSizeHigh) << 32);This code is extracting the two 32-bit halves of the value and passing them to the
MapViewOfFile()
function. In both cases the results need to be cast toDWORD
s to keep the compiler happy.PBYTE pbFile = (PBYTE)MapViewOfFile(hFileMapping, FILE_MAP_READ,
(DWORD)(qwFileOffset >> 32),
(DWORD)(qwFileOffset & 0xFFFFFFFF),
dwBytesInBlock);It's time for a new signature.
thank you very much.