SharedMemory

class dsviper.SharedMemory

Bases: object

A named memory region shared between processes.

Created or opened by name, so separate processes map the same bytes. Use create(…) or open(…). The bytes are read and written through StreamReaderSharedMemory and StreamWriterSharedMemory, which each take one of these; address() is the raw mapping, for foreign code that expects a pointer.

The object holds the mapping and releases it when the object itself goes, so there is nothing to close. The name is a separate thing that no object owns: unlink(name) is what removes it, and a name left behind can outlive every process that used it. exists(name) answers whether one is there.

Note: Not directly instantiable.

address() → int

Return the address the region is mapped at in this process.

static create(name: str, size: int) → SharedMemory

Create a region of size bytes, published under name.

static exists(name: str) → bool

Return True if a region is already published under name.

fd() → int

Return the file descriptor the region is mapped from; -1 on Windows, where a region is held by a handle, not a descriptor.

name() → str

Return the name the region is published under, which another process opens it by.

static open(name: str, size: int) → SharedMemory

Open the region published under name, mapping size bytes of it.

size() → int

Return the size of the region in bytes.

Remove the region published under name.