Sebastien Binet wrote:
> On Tuesday 02 June 2009 20:03:25 Lisandro Dalcin wrote:
>> On Tue, Jun 2, 2009 at 2:48 PM, Juha Salo wrote:
>>> OK, thanks for the info. It's interesting, though, that I can code
>>> something like this in Cython and it works:
>>>
>>> cdef class Foo:
>>> foos = {}
>>> def __cinit__(self, name):
>>> Foo.foos[name] = self
>>>
>>>>>> a = Foo('Larry')
>>>>>> b = Foo('Bob')
>>>>>> a.foos
>>> {'Bob': <foo.Foo object at 0x01C5F490>, 'Larry': <foo.Foo object at
>>> 0x01C5F488>}
>>>
>>>>>> b.foos
>>> {'Bob': <foo.Foo object at 0x01C5F490>, 'Larry': <foo.Foo object at
>>> 0x01C5F488>}
>> But that is a different beast. You are doing a 'getattr', and next
>> updating the attribute. What you cannot do on a cdef class is
>> 'setattr'. Python rules for extension types...
>>
>> BTW, such code creates reference cycles.
> which are usually easily broken if one were to use a
> weakref.WeakValueDictionar :)
... in which case the overhead is so high that you can just as well use a
plain Python class instead of an extension class.
[benchmark results left out as an exercise for the reader]
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev