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

David Beazley dave at dabeaz.com
Thu Sep 20 18:53:46 CEST 2012

How?  I must be missing something very obvious.


On Sep 20, 2012, at 11:48 AM, Benjamin Peterson wrote:

> 2012/9/20 David Beazley <dave at dabeaz.com>:
>> I have recently been experimenting with the memoryview() built-in and have come to believe that it really needs to expose the 'buf' attribute of the underlying Py_buffer structure as an integer (see PEP 3118).  Let me explain.
>> The whole point of PEP 3118 (as I understand it) is to provide a means for exchanging or sharing array data across different libraries such as numpy, PIL, ctypes, Cython, etc.   If you're working with Py_buffer objects at the C level, this works fine.  However, if you're working purely in Python, you're only able to get partial information about memory views such as the shape and size.   You can't get the actual pointer to the underlying memory (unless I've missed something obvious).
>> This is unfortunate because it means that you can't  write Python code to link memoryviews to other kinds of compiled code that might want to operate on array-oriented data.  For example, you can't pass the raw pointer into a function that you've exposed via ctypes.  Similarly, you can't pass the pointer into functions you've dynamically compiled using libraries such as LLVM-py.     There might be other kinds of applications, but just having that one bit of extra information available would be useful for various advanced programming techniques involving extensions and memory buffers.
> Presumably ctypes should be able to do this conversion for you.
> -- 
> Regards,
> Benjamin

More information about the Python-Dev mailing list