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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory mapped file I/O Vs Disk I/O

Memory mapped file I/O Vs Disk I/O

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiocomjsonperformancequestion
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.
  • V Offline
    V Offline
    vipin_nvk
    wrote on last edited by
    #1

    Hello Does memory mapped file I/O has a real advantage over disk I/O. Because I am trying to read a file using ::ReadFile API (block by block) and compare it with memory mapped file I/O mechanism from http://www.codeproject.com/KB/files/mmfio.aspx I then tried to compare the time taken to read a file of 700MB using both the techniques. I found that the memory mapped file I/O took almost the same time as disk I/O or sometimes more time. So, would like to know whether memory mapped file I/O does really provide an advantage over disk I/O and how do I achieve it. Thanks

    S 1 Reply Last reply
    0
    • V vipin_nvk

      Hello Does memory mapped file I/O has a real advantage over disk I/O. Because I am trying to read a file using ::ReadFile API (block by block) and compare it with memory mapped file I/O mechanism from http://www.codeproject.com/KB/files/mmfio.aspx I then tried to compare the time taken to read a file of 700MB using both the techniques. I found that the memory mapped file I/O took almost the same time as disk I/O or sometimes more time. So, would like to know whether memory mapped file I/O does really provide an advantage over disk I/O and how do I achieve it. Thanks

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      When reading the complete contents of a file, possibly not. However, with a big file, if you only want to read separate parts of the file, memory mapping gives you the convenience of memory-style accesses, and will only read the pages of the file you touch (whatever the page size of the VM system is). Consider if you wanted to read the first and last bytes of that file - you could map the whole file, read the first byte and the last byte and the disk IO system would have read two pages (2 x 4kB?). And you read those bytes through pointers. Another advantage - memory mapped IO sections can be defined using pointers (pointer to start, pointer to end), which are random-access iterators as far as the STL is concerned. File iterators in STL are forward-only iterators. I generally prefer to use memory-mapping when possible, as it's (IMO) easier to manage and use, mainly because of the STL related iterator thing.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      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