[Pyrex] first post, ref count problem

Josiah Carlson jcarlson at uci.edu
Thu Feb 1 01:42:45 UTC 2007


leonardo <leonmaf at yahoo.com> wrote:
> 
> Hello, this my first post here. I have started using
> Pyrex and this is just my second little Pyrex code:
> 
> http://rafb.net/p/Vm4S5E82.html
> 
> It's quite simple, it's a Chain class, that is a
> double linked list data structure, and I have to add
> many methods still.
> As you can see I've had to use void *pdata to allow it
> to accept items with Python objects references inside.

It seems to me that you are trying to mix ideas here.  Greg alluded to
it when he said, just use 'cdef class ...'.  In your later post, you
talked about trying to make the object fast.

In my experience, if you want/need to use Python as your main language,
then writing any "needs to be fast" code in C will be the fastest. 
Pyrex can add nice abstractions, but in this case, you may just be
better off with pure C.  After you have created your structure and its
manipulations in C, you can then wrap it with Pyrex, or perhaps have it
done automatically with Swig.

As for why the 'cdef class ...' version is slower and more memory hungry
than your old struct-based version, there are many possible reasons, not
the least of which that Objects in Python have nontrivial *extra* memory
use beyond the base object members (a type pointer and ref counter at
least), and that Pyrex may be doing more Increfs and Decrefs than
absolutely necessary.


In terms of switching to ObjectPascal or D; do whatever you think will
get to a satisfactory result.

 - Josiah




More information about the Pyrex mailing list