CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2011
    Posts
    44

    Sharing data between processes

    Hello,

    I have a developed an application which uses a complex data structure as data source. This data structure should exist only one time in memory. Every instance of my appliction should be able to access and change this data storage. (for e.g. a bunch of maps, lists and sets). What would be the best way to realize this? I thought about developing a Windows Service which uses boost inter- process communication? Is this doable or am I completely wrong?

    Kind regards,
    Michael

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Sharing data between processes

    Memory-Mapped File may be an option.
    Best regards,
    Igor

  3. #3
    Join Date
    Dec 2011
    Posts
    44

    Re: Sharing data between processes

    Hmm, doesn't this only work for files?

    Maybe I should describe a bit more detailed what I got.

    Currently I have a data handler class which provides several public functions and is a singleton instance (managing several data containers). This will only work for the current process which runs the data handler instance. So my idea was to 'outsource' my datahandler with it's data containers to have one single point of data handling for all my processes. The 'processes' are any windows program - my app is a namespace extension runing in the explorer.exe process, but the already buffered should be available in 'save as...' dialogs of any applications too. So that the data doesn't need to be reloaded again and again.

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Sharing data between processes

    Quote Originally Posted by chaos2oo2 View Post
    Hmm, doesn't this only work for files?
    No, MMFs can share any kind of data betweeen processes, and might be a good choice for your needs. See "Creating Named Shared Memory" at http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    Quote Originally Posted by MSDN Documentation
    To share data, multiple processes can use memory-mapped files that the system paging file stores.
    Mike

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Sharing data between processes

    So my idea was to 'outsource' my datahandler with it's data containers to have one single point of data handling for all my processes.
    Well, you always can do that. But this is not what they call sharing data. This is servicing data.
    Best regards,
    Igor

  6. #6
    Join Date
    Dec 2011
    Posts
    44

    Re: Sharing data between processes

    will it be possible to pass a pointer to an instance of an object (which will be in the shared memory) to the service method then? In case of a seperate process?

    @Igor:
    How is servicing data implemented?

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Sharing data between processes

    Pointers are valid only in context of an origin process. Passing pointers across process bounds are meaningless and must be avoided.

    Servicing data means some API or protocol for data exchange. It's up to you how you implement it, but the main point is that there is only single entity that performs physical data read and write with some persistent storage.
    Best regards,
    Igor

  8. #8
    Join Date
    Dec 2011
    Posts
    44

    Re: Sharing data between processes

    so as far as I see there is no easy way, I don't have the time to implement the whole data exchange on my own. What must be passed are lists of instances from my data handler.

    A process queries the data handler (by passing a pointer to an parent instance object) and receives a set of instance pointers. That's how it is implemented right now...using a singleton.

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Sharing data between processes

    Quote Originally Posted by chaos2oo2 View Post
    Currently I have a data handler class which provides several public functions and is a singleton instance (managing several data containers). This will only work for the current process which runs the data handler instance. So my idea was to 'outsource' my datahandler with it's data containers to have one single point of data handling for all my processes. The 'processes' are any windows program - my app is a namespace extension runing in the explorer.exe process, but the already buffered should be available in 'save as...' dialogs of any applications too. So that the data doesn't need to be reloaded again and again.
    That's a typical issue for a software architect which is sleeping with the GoF's little red book under the pillow and dreaming singleton (anti-)pattern with no clue about the given OS IPC (InterProcess Communications).
    So, please let me google for you: Windows InterProcess Communications
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  10. #10
    Join Date
    Mar 2012
    Posts
    1

    Re: Sharing data between processes

    I have tried different methods of sharing data between processes and found that good old named pipes work best. All other methods (such as shared memory, mapped files) do not work in Vista/7 because of their tight security. With the named pipes though, you need to use proper security descriptor in order to work in Vista/7.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured