6

I read that processes operate on seperate memory spaces (link). However the multiprocessing package of python offers shared memory (multiprocessing.Value, multiprocessing.Array).

  • Where (in which process) is this data stored?
  • Is the data accessed by reference by the child processes?
Oliver Wilken
  • 2,654
  • 1
  • 24
  • 34
  • it does not matter. – kindall Jun 17 '17 at 18:42
  • 1
    Perhaps the question should be, "How does Python share memory among multiple processes?" But to your specific questions, it has to be in the heap. It is not in any process space. When Python starts each process, it has to look at the declared shared variables and create memory space and references (answer to second question) in the heap. When a process uses it, the multiprocessing module does all of the memory locking to prevent data corruption, etc. There's a lot more to it than that, but that's the basics. – Ron Norris Jun 17 '17 at 18:54
  • 1
    This is also different depending on platform (for example windows) – anthony sottile Jun 17 '17 at 19:29
  • It's not Python, it's the operating system service. e.g. [shared memory](http://man7.org/linux/man-pages/man7/shm_overview.7.html). – Keith Jun 17 '17 at 20:01

1 Answers1

4

The data is allocated in a shared, anonymous memory map created through the mmap module. You can see the code here and here.

user2357112
  • 260,549
  • 28
  • 431
  • 505