On Sat 29 Aug 2009 at 08:36AM, Danek Duvall wrote: > Dan Price wrote: > > > http://cr.opensolaris.org/~dp/pkg-mem/ > > Nice. Very simple. > > I'm a bit confused about the protocol between __new__() and __init__(). > >From the datamodel doc page, __init__() is called if __new__() returns an > instance of the class. Which you do, so that's presumably when the > "dotstring" argument to __new__() is used. But since you're protecting > yourself against a second call, where does that second call come from?
The trick is that __init__ will be called as long as __new__ returns an instance of the class. So, if you return a completely new thing, or if you return a cached thing, __init__ is *still* called. A nice reference on this is here: http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#flyweight > You create a custom __setattr__() and __delattr__() to make the instances > immutable, but since this class derives from list, not tuple, do you do > anything to prevent the mutations lists typically allow? Should you define > __setitem__() and __delitem__()? Or should the class simply inherit from > tuple? I'm not sure. I'll try to look into it. The immutability was really just thrown in there, so maybe I should come back and do that another time. > I assume that _dotseq_pool is intended to be class-private. If so, it > should start with a double-underscore. Ok. > In __setattr__, the name of the class should have a capital S. > > In the perf test, you might get slightly more accurate numbers if you use > xrange() (a generator) instead of range() (a list), at least for the > 1..10000 case. Or you could predefine all three lists before getting > startusage. Or maybe all that is in the noise. Ok. I cross-checked my numbers against the results given by guppy/heapy (http://guppy-pe.sourceforge.net/) and they look sane, but you're right. I will work on it. -dp -- Daniel Price, Solaris Kernel Engineering http://blogs.sun.com/dp _______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
