boost::python, returning new PyObject references

David Abrahams david.abrahams at rcn.com
Mon Jan 7 19:14:48 CET 2002


----- Original Message -----
From: "Arnaldur Gylfason" <arnaldur at decode.is>


>
> > I don't think there's any reason that C++ functions which are generic
> over
> > python types need to be templated. I'd like to help people avoid
> templates
> > whenever its appropriate.
>
> Yeah maybe. I think is is easy to get used to template programming but of
> course if there is no benefit ...

There /is/ a benefit. For example, only a concrete function can be exported
to Python.

> Using template functions can of course cause code bloat.
> If we use inheritance I think we should consider virtual functions.
> Overriding non-virtual functions is normally
> considered bad practice.

In this case I think it would be fine, since the semantics would be
identical. The only advantage to using virtual functions is that invoking
operator[] on a python::sequence& bound to a python::list would be ever so
slightly faster... but the virtual function overhead might just as well
cancel that speed improvement out anyway.

> It can be argued there is no reason to override sequence methods in list.
> The PySequence_* calls should work the same as PyList_* calls.
> The difference is probably that PyList_* knows exactly what function to
> call (makes inlining possible ?)
> but PySequence_* has to use function pointers
> (o->ob_type->tp_as_sequence->sq_concat).

I don't think the extra level of indirection is really significant, but if
you really want to optimize I think replacing the non-virtual function is
the way to go.

-Dave




More information about the Cplusplus-sig mailing list