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. Is that sharing "memory" or sharing "file"?

Is that sharing "memory" or sharing "file"?

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
3 Posts 3 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.
  • S Offline
    S Offline
    sawerr
    wrote on last edited by
    #1

    Is using CreateFileMapping/MapViewOfFile functions means sharing "Memory" or "File" on the disk? I compiled that code for both -INVALID_HANDLE_VALUE, // use paging file (that is on the disk) and -"C:\\a.txt" //physical file too. All of them works. And second process can show "Message from first process". The second process calls: 1-) OpenFileMapping to get handle 2-) MapViewOfFile. What is happening here? Does second process get handle to physical "file" which is on the disk and get "Message from first process" string which is written by first process to file. or Second process get handle to first process' physical "memory" and get string from its address space? Are they communicating with writing/reading same file(pagefile or another file) on the disk or same memory? Msdn Documentation which is about procedure for sharing data with CreateFileMapping/MapViewOfFile/OpenFileMapping is confused me. Thanks.

    L G 2 Replies Last reply
    0
    • S sawerr

      Is using CreateFileMapping/MapViewOfFile functions means sharing "Memory" or "File" on the disk? I compiled that code for both -INVALID_HANDLE_VALUE, // use paging file (that is on the disk) and -"C:\\a.txt" //physical file too. All of them works. And second process can show "Message from first process". The second process calls: 1-) OpenFileMapping to get handle 2-) MapViewOfFile. What is happening here? Does second process get handle to physical "file" which is on the disk and get "Message from first process" string which is written by first process to file. or Second process get handle to first process' physical "memory" and get string from its address space? Are they communicating with writing/reading same file(pagefile or another file) on the disk or same memory? Msdn Documentation which is about procedure for sharing data with CreateFileMapping/MapViewOfFile/OpenFileMapping is confused me. Thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      The FileMapping stuff, when used by two processes on the same machine, is really sharing memory; it optionally uses a file as a backup or for persistency if you indicated that is what you want. I have used it once, for high-performance interprocess communication and it worked very well, much faster than straightforward file sharing would. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Voting for dummies? No thanks. X|


      1 Reply Last reply
      0
      • S sawerr

        Is using CreateFileMapping/MapViewOfFile functions means sharing "Memory" or "File" on the disk? I compiled that code for both -INVALID_HANDLE_VALUE, // use paging file (that is on the disk) and -"C:\\a.txt" //physical file too. All of them works. And second process can show "Message from first process". The second process calls: 1-) OpenFileMapping to get handle 2-) MapViewOfFile. What is happening here? Does second process get handle to physical "file" which is on the disk and get "Message from first process" string which is written by first process to file. or Second process get handle to first process' physical "memory" and get string from its address space? Are they communicating with writing/reading same file(pagefile or another file) on the disk or same memory? Msdn Documentation which is about procedure for sharing data with CreateFileMapping/MapViewOfFile/OpenFileMapping is confused me. Thanks.

        G Offline
        G Offline
        gayatri neelema
        wrote on last edited by
        #3

        Hi CreateFileMapping/MapViewOfFile is usually used in IPC(inter process communication) When you modify any particaluar file and want to be notified of the same in another application which do not drectly access the file , this is the mechmanism you would use. The second process would get the handle to first process physical memeory that is the reason you need to use critical section. Here there is only one copy of the file and when there is some change in the data then you could SENDMESSAGE WM_COPYDATA which also be received in the other application and thus there will be notifiaction of the data sent. I hope it answers your question.

        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