Code to get the memory address of a SharedMemory object

This commit is contained in:
Kovid Goyal 2023-01-25 09:13:00 +05:30
parent 1fecf2c380
commit 83891ed63e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -132,6 +132,15 @@ class SharedMemory:
self._size = size
@property
def memory_address(self) -> int:
import ctypes
obj = ctypes.py_object(self.mmap)
address = ctypes.c_void_p()
length = ctypes.c_ssize_t()
ctypes.pythonapi.PyObject_AsReadBuffer(obj, ctypes.byref(address), ctypes.byref(length))
return address.value
def read(self, sz: int = 0) -> bytes:
if sz <= 0:
sz = self.size