Memory sharing between 2 C# applications

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peri

    #1

    Memory sharing between 2 C# applications

    Dear All,

    Is there a way in which 2 application can share a common memory location to
    access static data?

    Say for example I have a product master data that is available in a single
    place, and I have an application that uses this data to do its own
    operation. I also have a similar kind of another application that uses the
    same data for its another operation. Can we implement this in C#?

    Regards,

    Peri


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Memory sharing between 2 C# applications

    Peri,

    Have you considered a database? One of the major features of a database
    is to be a persistent store of data for use by multiple applications. You
    can easily store state there that your other apps can use (assuming you are
    accessing the same database) and update as well.

    Sharing memory isn't a practical solution in .NET if you are going to
    share complex data structures (as you would have to manage the serialization
    to/from shared memory, and you would have to have some sort of locking
    mechanism on that memory). You are better off having a third app domain
    somewhere which will store the values/items you need, and then remote to
    that app domain to get/update those values/items.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Peri" <peri@CSPL.comw rote in message
    news:esTdPnWQIH A.1208@TK2MSFTN GP03.phx.gbl...
    Dear All,
    >
    Is there a way in which 2 application can share a common memory location
    to access static data?
    >
    Say for example I have a product master data that is available in a single
    place, and I have an application that uses this data to do its own
    operation. I also have a similar kind of another application that uses the
    same data for its another operation. Can we implement this in C#?
    >
    Regards,
    >
    Peri
    >

    Comment

    • Peri

      #3
      Re: Memory sharing between 2 C# applications

      DB access will be very slow compared to accessing the memory. Only because
      of this I am planning to have arrays similar to IMD(In-memory-database).
      Since there will not be any write operation I need not get worried about
      locking mechanism. It would be only read operation. If this is the case can
      I do it in a single machine (All applications running in one machine)?

      Regards,

      Peri

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:00CF2109-645D-42BD-B5AB-F4DD0DC7854C@mi crosoft.com...
      Peri,
      >
      Have you considered a database? One of the major features of a
      database is to be a persistent store of data for use by multiple
      applications. You can easily store state there that your other apps can
      use (assuming you are accessing the same database) and update as well.
      >
      Sharing memory isn't a practical solution in .NET if you are going to
      share complex data structures (as you would have to manage the
      serialization to/from shared memory, and you would have to have some sort
      of locking mechanism on that memory). You are better off having a third
      app domain somewhere which will store the values/items you need, and then
      remote to that app domain to get/update those values/items.
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Peri" <peri@CSPL.comw rote in message
      news:esTdPnWQIH A.1208@TK2MSFTN GP03.phx.gbl...
      >Dear All,
      >>
      >Is there a way in which 2 application can share a common memory location
      >to access static data?
      >>
      >Say for example I have a product master data that is available in a
      >single place, and I have an application that uses this data to do its own
      >operation. I also have a similar kind of another application that uses
      >the same data for its another operation. Can we implement this in C#?
      >>
      >Regards,
      >>
      >Peri
      >>
      >

      Comment

      • Rene

        #4
        Re: Memory sharing between 2 C# applications

        Is my understanding that you can have in memory data tables using a database
        such as sql server (I am assuming that you would be able to do this with the
        free express version too).



        If you use this technique you won't be reading and writing to disk, you will
        be reading and writing directly in and from memory.





        "Peri" <peri@CSPL.comw rote in message
        news:OVDwIyXQIH A.5208@TK2MSFTN GP04.phx.gbl...
        DB access will be very slow compared to accessing the memory. Only because
        of this I am planning to have arrays similar to IMD(In-memory-database).
        Since there will not be any write operation I need not get worried about
        locking mechanism. It would be only read operation. If this is the case
        can I do it in a single machine (All applications running in one machine)?
        >
        Regards,
        >
        Peri
        >
        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
        in message news:00CF2109-645D-42BD-B5AB-F4DD0DC7854C@mi crosoft.com...
        >Peri,
        >>
        > Have you considered a database? One of the major features of a
        >database is to be a persistent store of data for use by multiple
        >applications . You can easily store state there that your other apps can
        >use (assuming you are accessing the same database) and update as well.
        >>
        > Sharing memory isn't a practical solution in .NET if you are going to
        >share complex data structures (as you would have to manage the
        >serializatio n to/from shared memory, and you would have to have some sort
        >of locking mechanism on that memory). You are better off having a third
        >app domain somewhere which will store the values/items you need, and then
        >remote to that app domain to get/update those values/items.
        >>
        >--
        > - Nicholas Paldino [.NET/C# MVP]
        > - mvp@spam.guard. caspershouse.co m
        >>
        >"Peri" <peri@CSPL.comw rote in message
        >news:esTdPnWQI HA.1208@TK2MSFT NGP03.phx.gbl.. .
        >>Dear All,
        >>>
        >>Is there a way in which 2 application can share a common memory location
        >>to access static data?
        >>>
        >>Say for example I have a product master data that is available in a
        >>single place, and I have an application that uses this data to do its
        >>own operation. I also have a similar kind of another application that
        >>uses the same data for its another operation. Can we implement this in
        >>C#?
        >>>
        >>Regards,
        >>>
        >>Peri
        >>>
        >>
        >
        >

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Memory sharing between 2 C# applications

          I agree. For something like this, store the contents in a database,
          query for the information once, and then access the values from the DataSet
          (or whatever you stored the values to) from that point on.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Rene" <a@b.comwrote in message
          news:OtIluBYQIH A.3556@TK2MSFTN GP03.phx.gbl...
          Is my understanding that you can have in memory data tables using a
          database such as sql server (I am assuming that you would be able to do
          this with the free express version too).
          >
          >
          >
          If you use this technique you won't be reading and writing to disk, you
          will be reading and writing directly in and from memory.
          >
          >
          >
          >
          >
          "Peri" <peri@CSPL.comw rote in message
          news:OVDwIyXQIH A.5208@TK2MSFTN GP04.phx.gbl...
          >DB access will be very slow compared to accessing the memory. Only
          >because of this I am planning to have arrays similar to
          >IMD(In-memory-database). Since there will not be any write operation I
          >need not get worried about locking mechanism. It would be only read
          >operation. If this is the case can I do it in a single machine (All
          >applications running in one machine)?
          >>
          >Regards,
          >>
          >Peri
          >>
          >"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
          >in message news:00CF2109-645D-42BD-B5AB-F4DD0DC7854C@mi crosoft.com...
          >>Peri,
          >>>
          >> Have you considered a database? One of the major features of a
          >>database is to be a persistent store of data for use by multiple
          >>application s. You can easily store state there that your other apps can
          >>use (assuming you are accessing the same database) and update as well.
          >>>
          >> Sharing memory isn't a practical solution in .NET if you are going to
          >>share complex data structures (as you would have to manage the
          >>serializati on to/from shared memory, and you would have to have some
          >>sort of locking mechanism on that memory). You are better off having a
          >>third app domain somewhere which will store the values/items you need,
          >>and then remote to that app domain to get/update those values/items.
          >>>
          >>--
          >> - Nicholas Paldino [.NET/C# MVP]
          >> - mvp@spam.guard. caspershouse.co m
          >>>
          >>"Peri" <peri@CSPL.comw rote in message
          >>news:esTdPnWQ IHA.1208@TK2MSF TNGP03.phx.gbl. ..
          >>>Dear All,
          >>>>
          >>>Is there a way in which 2 application can share a common memory
          >>>location to access static data?
          >>>>
          >>>Say for example I have a product master data that is available in a
          >>>single place, and I have an application that uses this data to do its
          >>>own operation. I also have a similar kind of another application that
          >>>uses the same data for its another operation. Can we implement this in
          >>>C#?
          >>>>
          >>>Regards,
          >>>>
          >>>Peri
          >>>>
          >>>
          >>
          >>
          >
          >

          Comment

          • c.whelchel@gmail.com

            #6
            Re: Memory sharing between 2 C# applications

            On Dec 18, 6:33 am, "Peri" <p...@CSPL.comw rote:
            Dear All,
            >
            Is there a way in which 2 application can share a common memory location to
            access static data?
            >
            Say for example I have a product master data that is available in a single
            place, and I have an application that uses this data to do its own
            operation. I also have a similar kind of another application that uses the
            same data for its another operation. Can we implement this in C#?
            >
            Regards,
            >
            Peri

            Assuming you are doing this in Windows you can use the Win32 API calls
            CreateFileMappi ng, MapViewOfFile and OpenFileMapping . Look them up on
            pinvoke.net and msdn to find out how to setup a shared memory segment.
            It's pretty simple but for static data the database maybe a better way
            to go.

            Comment

            • christery@gmail.com

              #7
              Re: Memory sharing between 2 C# applications

              On 18 Dec, 12:33, "Peri" <p...@CSPL.comw rote:
              Dear All,
              >
              Is there a way in which 2 application can share a common memory location to
              access static data?
              >
              Say for example I have a product master data that is available in a single
              place, and I have an application that uses this data to do its own
              operation. I also have a similar kind of another application that uses the
              same data for its another operation. Can we implement this in C#?
              >
              Regards,
              >
              Peri
              Static data (thats not changing right?), read when app starts....from
              the registry or .ini file comes to mind.
              /CY

              Comment

              • Ben Voigt [C++ MVP]

                #8
                Re: Memory sharing between 2 C# applications


                "Peri" <peri@CSPL.comw rote in message
                news:OVDwIyXQIH A.5208@TK2MSFTN GP04.phx.gbl...
                DB access will be very slow compared to accessing the memory. Only because
                of this I am planning to have arrays similar to IMD(In-memory-database).
                Since there will not be any write operation I need not get worried about
                locking mechanism. It would be only read operation. If this is the case
                can I do it in a single machine (All applications running in one machine)?
                How much memory does the data take up? If it doesn't change, you can just
                read it into each app, no need for sharing. If its too big for that, you
                might use file APIs anyway, as Windows will use the file cache to avoid disk
                access, and the file cache is shared between all processes.
                >
                Regards,
                >
                Peri
                >
                "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
                in message news:00CF2109-645D-42BD-B5AB-F4DD0DC7854C@mi crosoft.com...
                >Peri,
                >>
                > Have you considered a database? One of the major features of a
                >database is to be a persistent store of data for use by multiple
                >applications . You can easily store state there that your other apps can
                >use (assuming you are accessing the same database) and update as well.
                >>
                > Sharing memory isn't a practical solution in .NET if you are going to
                >share complex data structures (as you would have to manage the
                >serializatio n to/from shared memory, and you would have to have some sort
                >of locking mechanism on that memory). You are better off having a third
                >app domain somewhere which will store the values/items you need, and then
                >remote to that app domain to get/update those values/items.
                >>
                >--
                > - Nicholas Paldino [.NET/C# MVP]
                > - mvp@spam.guard. caspershouse.co m
                >>
                >"Peri" <peri@CSPL.comw rote in message
                >news:esTdPnWQI HA.1208@TK2MSFT NGP03.phx.gbl.. .
                >>Dear All,
                >>>
                >>Is there a way in which 2 application can share a common memory location
                >>to access static data?
                >>>
                >>Say for example I have a product master data that is available in a
                >>single place, and I have an application that uses this data to do its
                >>own operation. I also have a similar kind of another application that
                >>uses the same data for its another operation. Can we implement this in
                >>C#?
                >>>
                >>Regards,
                >>>
                >>Peri
                >>>
                >>
                >
                >

                Comment

                • GG

                  #9
                  Re: Memory sharing between 2 C# applications

                  If you are looking for IPC then check named pipes. You will need dot net
                  3.5 version. hope it helps.



                  *** Sent via Developersdex http://www.developersdex.com ***

                  Comment

                  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                    #10
                    Re: Memory sharing between 2 C# applications

                    Peri wrote:
                    DB access will be very slow compared to accessing the memory. Only because
                    of this I am planning to have arrays similar to IMD(In-memory-database).
                    Since there will not be any write operation I need not get worried about
                    locking mechanism. It would be only read operation. If this is the case can
                    I do it in a single machine (All applications running in one machine)?
                    What about using a database with in memory tables like Oracle TimesTen ?

                    Arne

                    Comment

                    Working...