Nick Coghlan <ncoghlan <at> gmail.com> writes:
> 
> The big practical concern is actually the memory cost of adding yet
> another pointer (potentially 8 bytes of data) to every list object, even
> empty ones.

It needn't be, actually. Why?
You only need to store this other pointer when you have an orphaned area in the
first place. But then you can store the pointer *in* the orphaned area :-)

So let's say for example:
- when ob_size >= 0, there are no orphans
- when ob_size < 0, the pointer to the orphaned area is given by 
  (PyObject **) self->ob_items[-1]

This makes a couple of micro-operations slightly slower (you need to take
ob_size's absolute value to get the length (*)); and it kills code which uses
Py_SIZE() on lists. But PyList_GET_SIZE() exists for a reason.

(*) or you could use ob_size's MSB, and then a simple binary AND gets you the
length; or even ob_items's LSB, since the pointer will always be aligned on more
than 1 byte

(and, yes, this is a bit insane)

Regards

Antoine.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to