3

In the book "The Linux Programming Interface" it reads:

Although the code of a shared library is shared among multiple processes, its variables are not. Each process that uses the library has its own copies of the global and static variables that are defined within the library.

Is there an easier way for sharing the variables between two processes of the same library than using common IPC, like shm_open() and mmap()?

It feels overly complex sharing a class instance between two processes for a standard problem. Especially reading an already existing shared memory, how do I know e.g. the size of the class which I need to map into the processes memory?

ataraxis
  • 1,257
  • 1
  • 15
  • 30
  • 1
    What would be easier than mapping common memory locations? – stark Dec 09 '20 at 20:15
  • Using shared memory is not always the best plan. It's not especially portable, and there's a number of limitations. What's being shared here? Read-only data? Or live, read/write data? – tadman Dec 09 '20 at 20:20
  • 2
    It might also help if you elaborate on your context - what are you trying to achieve? – lxop Dec 09 '20 at 20:20
  • 1
    Based on the passage and what you posted in response, I'm not convinced you actually need to share instances of a variable. I think you may be confused as to how libraries tend to work. – dbush Dec 09 '20 at 22:31

0 Answers0