Fast array exchange between python and C++
aleax at aleax.it
Wed Jan 23 14:36:24 CET 2002
"Ja'zz" <ja at zz.emsmp.fr> wrote in message news:84adv5s5sv.fsf at zz.emsmp.fr...
> What is the recommended way to transfer arrays of numerical data from
> python to a C/C++ library and vise-versa? My current approach is to
> define the array in a C++ class, write put and get methods with indexes
> and use SWIG (-shadow) to access the methods in python. It works but
> creates loads of overhead.
> However, at this point, efficiency becomes a vital concern. How to I
> exchange an array of simple datatypes (doubles, integers and strings),
> such that they are read/write at both sides, with a minimum of overhead?
Look at module array in the standard Python library. It has
facilities for low-level access as well as being quite usable
from Python, as long as one-dimensional array of simple types
are indeed all you need.
If you need more than that, look at the Numeric extensions:
they define very powerful array facilities AND a C-level API.
More information about the Python-list