[Python-Dev] Why aren't more things weak referencable (original) (raw)
Christian Tismer tismer at stackless.com
Sun May 30 13:52:02 EDT 2004
- Previous message: [Python-Dev] Why aren't more things weak referencable
- Next message: [Python-Dev] Why aren't more things weak referencable
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bob Ippolito wrote:
On May 29, 2004, at 1:06 PM, Raymond Hettinger wrote:
Instances of classes inheriting from str, tuple, etc cannot be weakly referenced. Does anyone know the reason for this? They can not accept non-empty slots either, which is probably closer to the source of the problem. I have no idea what the reason is. I imagine it's something to do with optimization, and/or because they are immutable.
it is because they are var-sized objects. There is no place to put the weakref pointer in, since the variable part starts right at the beginning of the object.
This is not really necessary, because strings are not so var-sized at all. After creation, they are fixed sized, and we could implement special cases for all such types, similar to what I did with type objects and slots.
The property of "var-sized" objects is everything else but being var-sized. They are fixed sized after initialization, just that you cannot have fixed offsets at "compile time". The real var-sized objects are fixed-size :-)) , because they use an extra memory area to grow or shrink at runtime.
I think slots could be added to all var-sized objects, and weakref is nothing else but kind of slot. The cost would be a little more computation and some special macro which points to the area "behind" the object. See my special case for meta types in Stackless typeobject.c.
ciao - chris
-- Christian Tismer :^) <mailto:tismer at stackless.com> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : Starship http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
- Previous message: [Python-Dev] Why aren't more things weak referencable
- Next message: [Python-Dev] Why aren't more things weak referencable
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]