Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. about Operator of >> and << in the Memory-Mapping Files.

about Operator of >> and << in the Memory-Mapping Files.

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lxlenovostar
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • L lxlenovostar

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 to DWORDs 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.

      L 1 Reply Last reply
      0
      • L Lost User

        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 to DWORDs 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.

        L Offline
        L Offline
        lxlenovostar
        wrote on last edited by
        #3

        thank you very much.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups