[Pyrex] class or extention type
Lenard Lindstrom
len-l at telus.net
Fri Oct 8 17:23:43 CEST 2004
On Thu, 07 Oct 2004 23:48:06 -0700 Bryan Weingarten <bryan.weingarten at pobox.com> wrote:
> i thought i asked this question before, but i can't seem to find it
> with google, so i'll ask again... with pyrex, what is the difference
> between creating a class "class Foo" and an extension type "cdef class
> Foo"? how do i know which one i should create? is there a simple
> criteria to know which is the right one? is there an
> advantage/disadvantage?
>
class Foo creates a python class just as expected. Instance attributes are
kept in a dictionary so they can be dynamically added and removed. It
also supports weak references. Usually it is just as good to do the same
declaration in a Python module. In Pyrex they make sense if you are including
some C code in the methods.
Python's builtin types int, double, list, etc. are extension types. These
wrap C structures. Attributes are actual pointer offsets rather that entries
in a dictionary. They are used when writing a Python wrapper for a C library.
Also some python classes can be rewritten as extension types to improve
performance and reduce memory requirements. But Pyrex extension types only allow
single inheritance. And at present instances have only fixed attributes and no weak
reference support.
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list