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 Memory-Mapped Files do with the big file.

about Memory-Mapped Files do with the big file.

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelp
2 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

    i have wirtten a demo, which i want to chip the big file into the small ones by Memory-Mapped Files. the main code: HANDLE hFile = CreateFile(filePathName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, dwCurPart); HANDLE hNewFile = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hNewFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwCurPart, NULL); PVOID pvNewFile = MapViewOfFile(hNewFileMap, FILE_MAP_WRITE, 0, 0, 0); memcpy(pvNewFile, pvFile, dwCurPart); i can get the new files,but the file don't get any content.i think the "memcpy();" can let the content copy into the new files. thanks for your help.

    _ 1 Reply Last reply
    0
    • L lxlenovostar

      i have wirtten a demo, which i want to chip the big file into the small ones by Memory-Mapped Files. the main code: HANDLE hFile = CreateFile(filePathName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, dwCurPart); HANDLE hNewFile = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hNewFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwCurPart, NULL); PVOID pvNewFile = MapViewOfFile(hNewFileMap, FILE_MAP_WRITE, 0, 0, 0); memcpy(pvNewFile, pvFile, dwCurPart); i can get the new files,but the file don't get any content.i think the "memcpy();" can let the content copy into the new files. thanks for your help.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You have set the dwNumberOfBytesToMap parameter for the destination file to 0. Memory mapped files cannot grow like a disk files. You have to create the destination file with blanks and set the dwNumberOfBytesToMap to the desired number of bytes. To create a blank file use SetEndOfFile after the CreateFile call.

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      modified on Tuesday, May 25, 2010 12:09 PM

      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