First cpp stands for C Pre Processor, this tool usually does macro
substitution in c, objective c, c++. Hence Cpp in the object is pretty
much confusing when it seems to be talking about C++.
2012/4/27 Benjamin Root <ben.root@...1304...>:
I was wondering if it is possible to use matplotlib from C++ directly
and I have found an example on how to do this on StackOverflow:
Well, using that "method", you could interface with any python libraries in
C++, but you wouldn't be able to do anything useful.
I dont quite get it Ben.
The stackoverflow is pretty revelant.
using #include <python.h> is smart: you can avoid all the free/malloc
in GC byt using python data structure and use this in your C code. And
I know C/C++ dev using this trick in real open source project since
python.h is less complicated to use than all the kombinat from boost.
But, I would not use this method. (Question of taste and of
There is another simpler solution however :
Do everything in python : python is a very powerfull gluing langage,
the GIL ensuring that non thread-safe code is thread safe, it is very
forgiving with code not design for concurrency.
***** ctypes permits the direct loading and binding with C++ classes,
or C functions.
**** Another solution that seems impressive, is writing C/C++
extensions in python. It is very easy (I self learnt it in one day
even though IQ test rank me 20 points below average).
The benefit is you could use your C++ code to return native python
object (set, array, dict, string, unicode, int (arbitrary long int)
My advice for big stream of data is you can return an iterator on the
stream of data, thus limiting the memory usage if it is important
(dont if you dont need it, premature optimization is the root of all
if your c++ code becomes an extension of python, it's deployment in an
ecosystem of python instances will be made easier through the use of
This gluing will ensure your data will flow without all the quirks
related to popen (caching of stdout/in, no control on mermory use ,
interruptions, portability issues ...).
The first solution is easy to achieve, the second solution requires
more time but is funnier.
On Fri, Apr 13, 2012 at 4:24 PM, Ignas Anikevicius <anikevicius@...287...> > wrote: