I am using Boost.Python to extend python program functionality. Python scripts do a lot of calls to native modules so I am really concerned about the performance of python-to-cpp type conversion and data marshaling.
I decided to try exposing methods natively through Python C API. May be somebody already tried that before ? Any success … at least in theory ?
The problem I run into is that how to convert PyObject* back to class instance, PyArg_parse provides O& option, but what I am looking is simply a pointer to C++ object in memory… how can I get it in function ?
if ( PyArg_ParseTuple(args, "O", &pyTestClass ) )
{
// how to get TestClass from pyTestClass ??
}
Thanks
I haven’t tried Boost.Python, but I’ve extended Python using raw C as well as Cython. I recommend Cython; if you’re careful enough you can get code with the same efficiency as raw C but with a lot less boilerplate code.
Regarding efficiency, it’s relative. It depends on what you want to do and how you do it. For example, what I’ve done very often is write the inner loop of some image processing or matrix operation in C, and have this function be called by Python with pointers to matrices as arguments. The matrices themselves don’t get copied, so the overhead is minimal.