On Tuesday 02 June 2009 20:03:25 Lisandro Dalcin wrote:
> On Tue, Jun 2, 2009 at 2:48 PM, Juha Salo <[email protected]> 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 :)

> If you are going to create a
> lot of these objects, GC collection will have to traverse a large
> dict, slowing down your runs each time the collection triggers.

cheers,
sebastien.
-- 
#########################################
# Dr. Sebastien Binet
# Laboratoire de l'Accelerateur Lineaire
# Universite Paris-Sud XI
# Batiment 200
# 91898 Orsay
#########################################

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to