-3

The following code runs without error on macOS:

from multiprocessing.shared_memory import SharedMemory shm = SharedMemory(create=True, size=4) for b in shm.buf: assert b == 0 shm.close() shm.unlink() 

This indicates that the shared memory segment is all binary zero.

However, what I want to know is whether this is well-defined behaviour across all platforms

3
  • It's better to consider the contents indeterminate, and always explicitly initialize it if you need to. Commented Sep 2, 2022 at 7:22
  • It's more about OS. In Windows SharedMemory relies on CreateFileMapping()/OpenFileMapping() calls, in POSIX it calls shm_open(). Commented Sep 2, 2022 at 7:23
  • @VsevolodTimchenko Thank you . I did search but obviously didn't use the right terms Commented Sep 2, 2022 at 7:23

1 Answer 1

0

This is a duplicate:

Why does python's SharedMemory seem to initialize arrays to zeros

This is operating system dependent. Python doesn't initialize the memory - it just takes the virtual memory address offered by the operating system.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.