[Python-ideas] Save memory when forking with *really* immutable objects

Barry Warsaw barry at python.org
Fri Mar 23 01:40:14 CET 2012

On Mar 12, 2012, at 08:49 PM, Gregory P. Smith wrote:

>If reference counts were moved out of the PyObject structure into a region
>of memory allocated specifically for reference counts, only those pages
>would need copying rather than virtually every random page of memory
>containing a PyObject.  My initial thought was to do this by turning the
>existing refcount field into a pointer to the object's count or an array
>reference that code managing the reference count array would use to
>manipulate the count.  Obviously either of these would have some
>performance impact and break the ABI.

It's been *ages* since I really knew how any of this worked, but I think some
flavor of the Objective-C runtime did reference counting this way.  I think
this afforded them other tricks, like the ability to not increment the
refcount for an object if it was exactly 1.  I've no doubt someone here will
fill in all my faulty memory and gaps, but I do seem to recall it being a
pretty efficient system for memory management.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120322/ea413778/attachment.pgp>

More information about the Python-ideas mailing list