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. Sharing dynamically allocated data across DLL instances?

Sharing dynamically allocated data across DLL instances?

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 5 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.
  • J Offline
    J Offline
    Jim A Johnson
    wrote on last edited by
    #1

    I'm working on an architecture that will require a DLL to host a singleton object that will be accessible by multiple applications. It's clear that I can store the pointer to the singleton in a shared data segment, so that it will be used by all instances of the DLL... but the pointer will point to a dynamically allocated object, which itself will contain pointers to other dynamically allocated objects. Now as I understand it, these DA'd objects will be mapped into the address space of the app that first loade the DLL, correct? This means they won't be accessible to other applications, correct? If my logic is correct.. how can I share these objects between instances? Color me puzzled.

    S M L 3 Replies Last reply
    0
    • J Jim A Johnson

      I'm working on an architecture that will require a DLL to host a singleton object that will be accessible by multiple applications. It's clear that I can store the pointer to the singleton in a shared data segment, so that it will be used by all instances of the DLL... but the pointer will point to a dynamically allocated object, which itself will contain pointers to other dynamically allocated objects. Now as I understand it, these DA'd objects will be mapped into the address space of the app that first loade the DLL, correct? This means they won't be accessible to other applications, correct? If my logic is correct.. how can I share these objects between instances? Color me puzzled.

      S Offline
      S Offline
      Stephen Kellett
      wrote on last edited by
      #2

      You are correct they will be in their private address space. However you could pass messages with object index in them. Each process would have its own objects and you'd gain access to them via the object index/id which you would use as a hashtable key/array index/ whatever. You could also try something with a memory mapped file. All processes could map the same file and try for the same load address. Then write your objects in there. Yuck. Or worse, they don't load at the same address, so them you are down to offsets from the memory mapped file address. Double yuck. Can't think of anything for now... Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.

      J 1 Reply Last reply
      0
      • S Stephen Kellett

        You are correct they will be in their private address space. However you could pass messages with object index in them. Each process would have its own objects and you'd gain access to them via the object index/id which you would use as a hashtable key/array index/ whatever. You could also try something with a memory mapped file. All processes could map the same file and try for the same load address. Then write your objects in there. Yuck. Or worse, they don't load at the same address, so them you are down to offsets from the memory mapped file address. Double yuck. Can't think of anything for now... Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.

        J Offline
        J Offline
        Jamie Nordmeyer
        wrote on last edited by
        #3

        I don't have too much experience with them, but couldn't you use an Atom if it's a string value that you're trying to store? Do Atoms work for non-string items? Jamie Nordmeyer Portland, Oregon, USA

        1 Reply Last reply
        0
        • J Jim A Johnson

          I'm working on an architecture that will require a DLL to host a singleton object that will be accessible by multiple applications. It's clear that I can store the pointer to the singleton in a shared data segment, so that it will be used by all instances of the DLL... but the pointer will point to a dynamically allocated object, which itself will contain pointers to other dynamically allocated objects. Now as I understand it, these DA'd objects will be mapped into the address space of the app that first loade the DLL, correct? This means they won't be accessible to other applications, correct? If my logic is correct.. how can I share these objects between instances? Color me puzzled.

          M Offline
          M Offline
          Matt Gullett
          wrote on last edited by
          #4

          Is an NT service an option? If so, this is a good way to do what you asked. If not (and MFC is an option), look at the CMemFile class. There are samples on MSDN. If MFC and CMemFile are not an option you can still use API functions to create memory mapped files. Check out this link to the MSDN library: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/hh/winbase/dll\_9khl.asp If none of these options will work for you, you can create a second EXE which will host a named pipe or other inter-process communication layer (TCPIP listner) which can be launched to distribute the data. (This is probably overkill, though.) Thanks Matt Gullett

          1 Reply Last reply
          0
          • J Jim A Johnson

            I'm working on an architecture that will require a DLL to host a singleton object that will be accessible by multiple applications. It's clear that I can store the pointer to the singleton in a shared data segment, so that it will be used by all instances of the DLL... but the pointer will point to a dynamically allocated object, which itself will contain pointers to other dynamically allocated objects. Now as I understand it, these DA'd objects will be mapped into the address space of the app that first loade the DLL, correct? This means they won't be accessible to other applications, correct? If my logic is correct.. how can I share these objects between instances? Color me puzzled.

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

            I have extensive experience with shared memory and, to the best of my knowledge, what you are attempting is not possible. What you could do though is separate the data from the methods and declare structures that you place in a memory mapped file. You could then create objects that map to invidual instances of the data structures. I have done similar things and, while it isn't exactly clean, it is workable and not overly complex. Unfortunately, character strings must be either of fixed length or allocated from a 'pool' of characters. If the data structures are highly dynamic then the fixed length option is probably better. Best of luck.

            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