ctypes And The WACAH Principle

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Aug 10 02:35:44 EDT 2016


Lawrence D’Oliveiro wrote:
> When using array objects from code written in C or C++ (the only way to 
> effectively make use of this information), it makes more sense to use the 
> buffer interface supported by array objects.
> 
> Ah, I wish... I had a look at the documentation for the buffer interface and
> memory views, and found no way to make use of them from pure Python.
> Basically, the paragraph I quoted above is wrong in just about every
> important detail.

I think you must be misreading it. It's talking about accessing
the internals of an object from C or C++ code, *not* from Python.

If I understand correctly, you want to get the address of an
object's memory as a Python integer, so that you can pass it to
something via a ctypes wrapper?

If you're using ctypes anyway, it shouldn't be much harder to
use ctypes to access the object's buffer interface, if it has
one.

You could also consider using Cython instead of ctypes. It will
let you create non-leaky wrappers and provide easy access to
buffer interfaces.

-- 
Greg



More information about the Python-list mailing list