speeding things up with C++

Jorgen Grahn grahn+nntp at snipabacken.dyndns.org
Wed May 30 16:04:01 EDT 2007


On 26 May 2007 02:19:39 -0700, bullockbefriending bard <kinch1967 at gmail.com> wrote:
...
> Essentially, I need to pass a list of 6-tuples containing only
> integers to my new sadly necessary super-fast compiled language
> function which i am not looking forward to writing:
>
> input: [(1,2,3,4,5,6), (7,8,9,10,11,12),...]
>
> and after much thrashing of processor resources, return data which
> looks like this to the Python calling environment:
>
> output: [( (1, 2), (1,), (12,), (13), (1, 7, 11), (9,) ), (  another
> nested tuple like preceding one  ), .... ]
...
> However, I hope someone reading this will be able to tell me that I'm
> being a total pessimist and that in fact it isn't very difficult to do
> what I want to do using SWIG.

You're talking about the actual conversion between Python data
structures and C or C++ data structures?  That is easy to do even
manually, IMHO -- provided a decent C background.

Have a look in the Python/C API Reference Manual, and the mapping
becomes clear. The PyListObject stuff for example, where there's a C
function for every basic operation on lists, and where the elements
have the C type PyObject. And so on.  Mapping to C is just a matter of
walking a nested data structure, where you have a good idea what it is
supposed to look like (a list of six-tuples of some kind of numbers).

/Jorgen

-- 
  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/     snipabacken.dyndns.org>  R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list