20 Sep
2012
20 Sep
'12
5:57 p.m.
On 20/09/2012 5:53pm, David Beazley wrote:
How? I must be missing something very obvious.
I would not call it obvious, but you can do >>> m = memoryview(bytearray(5)) >>> ctypes.addressof(ctypes.c_char.from_buffer(m)) 149979304 However, this only works for writable memoryviews. For read-only memoryviews you could do >>> obj = ctypes.py_object(m) >>> address = ctypes.c_void_p() >>> length = ctypes.c_ssize_t() >>> ctypes.pythonapi.PyObject_AsReadBuffer(obj, ctypes.byref(address), ctypes.byref(length)) 0 >>> address, length (c_void_p(149979304), c_long(5))