[Python-Dev] Class/type dichotomy thoughts

Greg Ewing greg@cosc.canterbury.ac.nz
Mon, 06 Nov 2000 16:19:28 +1300 (NZDT)


> [MAL]
> > One thing that would probably be implementable is a way to
> > maintain "instance" dictionaries for types

> But this would require an extra pointer field for *all* built-in
> types.

Ruby has an interesting solution to this. It keeps such
"extra" instance variables in a global data structure.

The Python version of this would be to have a special global
dict which maps instances of built-in types to dicts holding
their extra instance variables.

The keys in this dict would have to be weak references,
so that they wouldn't keep the objects alive. A flag would
be set in the object header so that, when the object was
deleted, the corresponding entry in the global dict
could be cleaned up.

The overhead would then be one bit in each object, and
one extra test when deleting an object.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+