[Tutor] Moving my C++ code to Python?

Paul paulanon at gmail.com
Sun Oct 17 23:29:30 CEST 2010


Thank you all for your kind suggestions.  It seem that cython and
boost.python both look like a good suggestions; SWIG seems like a good
tool, but may not meet my requirements.
Quick google seems to suggest that boost.python is 7 times slower [1],
however.  Any thoughts about speed performance between the two?

[1] http://blog.chrischou.org/2010/02/28/simple-benchmark-between-cython-and-boost-python/

Thank you,
Paul

And a link I found today.
[2] http://koichitamura.blogspot.com/2008/06/various-ways-to-integrate-python-and-c.html

On Sun, Oct 17, 2010 at 1:56 PM, Sithembewena Lloyd Dube
<zebra05 at gmail.com> wrote:
> Also have a look at Boost.Python:
>
> http://www.boost.org/doc/libs/1_44_0/libs/python/doc/index.html
>
> On Fri, Oct 15, 2010 at 11:29 PM, Paul <paulanon at gmail.com> wrote:
>>
>> Hi there,
>>
>> I've been using C/C++ for many years (python, just reading about it).
>>
>> I have a software written in C/C++ but considering porting most of it
>> to python, as it seems like it's a better choice for decision making
>> portion of the code.  I'm also thinking about having a 'matlab' like
>> interface for reading, processing, and writing.
>>
>> In my current C++ code, I would read data into a vector of structs
>> (which contains other simple vectors, strings, and structs) and it can
>> be as large as 500MB to 2GB.  The data gets processed (requires random
>> access).  The result is then written out.
>>
>> I would like to make modules for python.  The problem is that the
>> vector of structs that is very large.  First, is it possible to pass
>> such structures around to and from python and C/C++?  What would be
>> the overhead cost of having a large structure that needs to be passed
>> to and from the C/C++ modules?
>>
>> # I imagine I'd use the newly written software this way:
>> >>> import c_stuff  # my C/C++ module
>> >>> largestuff = c_stuff.read(file)  # read from disk
>> >>> c_stuff.process(largestuff, someparams1)  # processing, requires
>> >>> random access to the vector
>> >>> c_stuff.process(largestuff, someparams2)
>> ...
>> >>> c_stuff.process(largestuff, someparams10000) # the whole thing may
>> >>> take a few minutes to days
>> >>>
>> >>> import python_stuff # some module written in python to process the
>> >>> data as well
>> >>>
>> >>> python_stuff.process(largestuff, otherparams1)  # It's important that
>> >>> this data can be read (and I hope written) by python code
>> >>> python_stuff.process(largestuff, otherparams2)
>> >>>
>> >>> c_stuff.write(largestuff) #write result
>>
>> Thank you in advance,
>> Paul
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>


More information about the Tutor mailing list