[Numpy-discussion] Pointer to array data for passing to swig-wrapped C++

Peter numpy-discussion at maubp.freeserve.co.uk
Mon Aug 24 16:08:33 EDT 2009


On Mon, Aug 24, 2009 at 8:37 PM, Angus McMorland<amcmorl at gmail.com> wrote:
>
> Hi all,
>
> Our lab has an in-house messaging protocol, written in C++, for
> interfacing the different components of our experimental setups, and
> allowing programs written in several different languages to talk to
> each other. I'm currently trying to write a Python interface to this
> protocol, mainly so I can show people here how good a Traits-based GUI
> would be for controlling things. I'm not familiar with interfacing C++
> and Python code, so this is a little hit and miss, and any suggestions
> on better approaches would be welcome. I have wrapped the C++ code in
> swig, and can now call the simple routines from within Python.
>
> The trouble I'm having is constructing new message data, and passing a
> reference to that data. Each message consists of a ID code telling us
> what type of message it is, a buffer of data, of which some subset is
> actually useful, and the number of bytes of the buffer that have been
> filled with useful data. I can get message data out of a message
> constructed and sent by some other implementation of the protocol by
> reading it into a numpy array with a dtype matching the structure of
> the data being sent, and calling, for example ...

Have you considered using the Python struct module? If your "buffer
of data" is a mixture of fields, this might be a better match than using
numpy. See http://docs.python.org/library/struct.html

Peter



More information about the NumPy-Discussion mailing list