mutable ints: I think I have painted myself into a corner

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun May 19 21:23:28 EDT 2013


Cameron Simpson wrote:
> It's an int _subclass_ so that it is no bigger than an int.

If you use __slots__ to eliminate the overhead of an
instance dict, you'll get an object consisting of a
header plus one reference, which is probably about the
size of an int. But you'll also need an int to put in
that slot, so the total size will be about twice that
of an int.

Another approach would be to subclass array.array and
give instances of it type integer and size 1. Together
with empty __slots__, it will probably be a bit bigger
than an int, but it might still be smaller than a
custom object plus an int.

If all of these are still too big, you might need to
find some way of packing multiple instances into a
single array.array.

-- 
Greg



More information about the Python-list mailing list