Read the memory from both C program and C++ program simultaneously

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyachari
    New Member
    • Jan 2007
    • 11

    Read the memory from both C program and C++ program simultaneously

    Hi ,

    Can anyone suggest me how to read the contents from an Array from C program while the array is actually populated from another program in C++

    More specifically, what i like to do is read some dynamic information from a file, populate into the memory so that both the C program and C++ program can access the runtime contents? Also, i'm working in an UNIX environment!

    Thanks in Advance
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    If this file is more or less static you may consider simply reading this file in each program.

    If you really need to support in-memory communication between two (or more) processes, then read on System V IPC (Inter-Process Communication)

    I think you can employ some of the IPC facilities, named pipes, or shared memory.

    Comment

    • priyachari
      New Member
      • Jan 2007
      • 11

      #3
      Thx michael.

      But i need it since, there will be a more than 1 request trying to read and write the file concurrently. Hence, i need the file content, say for eg code,descriptio n and count to be prepopulated into memory and be able to update the count concurrently. Also, the update can be performed either from C++ program or C program also.

      Can u suggest me, if fork can be of any use in this case...or should i go for IPC. i tried to populate the content by always loading the array content repeatedly in the memory using an indefinite loop ...but i wasnt able to read the content from another call though...

      Thanx in advance

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by priyachari
        Thx michael.

        But i need it since, there will be a more than 1 request trying to read and write the file concurrently. Hence, i need the file content, say for eg code,descriptio n and count to be prepopulated into memory and be able to update the count concurrently. Also, the update can be performed either from C++ program or C program also.

        Can u suggest me, if fork can be of any use in this case...or should i go for IPC. i tried to populate the content by always loading the array content repeatedly in the memory using an indefinite loop ...but i wasnt able to read the content from another call though...

        Thanx in advance

        Are you writing both the C and the C++ program?

        Comment

        • priyachari
          New Member
          • Jan 2007
          • 11

          #5
          Motoma,

          Yes, both C and C++ program needs to be run and i'm writing both of them...

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by priyachari
            Motoma,

            Yes, both C and C++ program needs to be run and i'm writing both of them...
            Here is a decent article on the matter.

            Comment

            • horace1
              Recognized Expert Top Contributor
              • Nov 2006
              • 1510

              #7
              Originally posted by priyachari
              Motoma,

              Yes, both C and C++ program needs to be run and i'm writing both of them...
              also have a look at
              http://www.cs.cf.ac.uk/Dave/C/node27.html

              for IPC pipes, semaphores, messages, shared memory, etc

              Comment

              • priyachari
                New Member
                • Jan 2007
                • 11

                #8
                Originally posted by horace1
                also have a look at
                http://www.cs.cf.ac.uk/Dave/C/node27.html

                for IPC pipes, semaphores, messages, shared memory, etc
                Thanks a lot for the article. The sample seems to solve pretty much the problem...

                Comment

                • priyachari
                  New Member
                  • Jan 2007
                  • 11

                  #9
                  Originally posted by Motoma
                  Thanks Motoma...The article is really good...

                  Comment

                  Working...