A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-September/121780.html below:

[Python-Dev] Memoryviews should expose the underlying memory address

[Python-Dev] Memoryviews should expose the underlying memory address [Python-Dev] Memoryviews should expose the underlying memory addressRichard Oudkerk shibturn at gmail.com
Thu Sep 20 19:57:37 CEST 2012
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))


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4