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


Groups > comp.lang.python > #45587

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

Date 2013-05-20 16:07 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: mutable ints: I think I have painted myself into a corner
References <avtc8iFp5vU1@mid.individual.net>
Newsgroups comp.lang.python
Message-ID <mailman.1860.1369030093.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 20May2013 13:23, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
| 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.

Yeah, I was thinking I'd need to go that way. Thanks for the
suggestion.

| 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.

Really? Interesting. I thinik it crosses my "too baroque" threshold,
but maybe not:-)

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

Space isn't that real an issue at present; I'll keep that kind of
approach in mind if it comes up. This really came up because I was
feeling that the obvious object-with-boolean-attributes was terrbily
wasteful for something that can be inplemented with a single int,
in principle.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

>>>How do you blip the throttle and wave? Do you blip it real high, then wave
>>>before the revs drop back?
>>Blip = right hand; Wave = left hand.  Do both simultaneously.  QED.
>Doesnt this make the bike lurch forward thru the intersection?
Not if the disk lock is in place...
        - Dean Woodward <deanw@agora.rdrop.com>

Back to comp.lang.python | Previous | NextPrevious 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