[C++-sig] static arrays to Python

Frederick Heckel entropydevice at gmail.com
Mon Sep 29 15:21:23 CEST 2008


Hi,

I have a series of structs which contain static arrays of more custom
structs and some built-in types. One example:

struct connectivity
{
   int       connections[SSPS_MAX_GATEWAYS];
   gateway   gateways[SSPS_MAX_GATEWAYS];
   int       adjacents[SSPS_MAX_ADJACENTS];
};

In every case, the arrays are static, as in this case, where
SSPS_MAX_GATEWAYS is #defined to 16. Previously, these were moved
around via shared memory in C. We're now moving to Python, and find
ourselves having to use named pipes in windows, because of the general
weirdness of Vista. But we are still using some of our old services,
including the one that generates this struct (and several more like
it); it seemed as though it should be fairly straightforward to wrap
all the functionality in a class, and invoke that via Python.

But dealing with these static arrays is turning out to be an enormous
pain. I initially tried iterating over them to turn them into
boost::python lists, but we'd like to be able to use pickle to turn
them into strings to send over the pipe. Pickle is having none of it.

So my question is, what am I missing? These are contiguous blocks of
memory, boost::python has no trouble wrapping the individual structs,
so long as I use accessors for the static arrays, but it looks like
the task of getting them set up for pickle is going to be a massive
PITA. It seems like there should be some [relatively] easy, efficient
way to get static arrays into python (even discarding the use of
pickle for now, we'll assume they don't need to be mutable from
python), but I'm not finding it.

I'll rewrite the whole silly service in Python if I have to, but it
seems like there should be a Better Way.

-- 
(fwph)

Frederick Heckel



More information about the Cplusplus-sig mailing list