Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45578

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: mutable ints: I think I have painted myself into a corner
Date Mon, 20 May 2013 13:23:28 +1200
Lines 22
Message-ID <avtc8iFp5vU1@mid.individual.net> (permalink)
References <CAPTjJmrgFGP=4pHXN7cKRzZ4pNg1Yeki=iPFw9bRLDF-osYAaA@mail.gmail.com> <mailman.1828.1368928471.3114.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net 8q+Yc27sdc2jk4C1QUfMZAwRpN7WnAchHQrIeqVJya1WJaZLn1
Cancel-Lock sha1:BSB/mGfdbqIy9JbeAUjxGvM2Gcg=
User-Agent Mozilla Thunderbird 1.0.5 (Macintosh/20050711)
X-Accept-Language en-us, en
In-Reply-To <mailman.1828.1368928471.3114.python-list@python.org>
Xref csiph.com comp.lang.python:45578

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: mutable ints: I think I have painted myself into a corner Cameron Simpson <cs@zip.com.au> - 2013-05-19 11:54 +1000
  Re: mutable ints: I think I have painted myself into a corner Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-05-20 13:23 +1200
    Re: mutable ints: I think I have painted myself into a corner Cameron Simpson <cs@zip.com.au> - 2013-05-20 16:07 +1000

csiph-web