How to use a 5 or 6 bit integer in Python?

Glen Wheeler adsl5lcq at
Fri Dec 19 04:55:04 CET 2003

On 19 Dec 2003 13:59:44 +1050, Ben Finney
<bignose-hates-spam at> wrote:

>On Fri, 19 Dec 2003 11:42:49 +1100, Glen Wheeler wrote:
>>   My program uses many millions of integers, and Python is allocating
>> way too much memory for these.
>How have you measured this?  As pointed out by others, Python doesn't
>have duplicate occurrences of identical integers; it refers to the same
>object multiple times.
>Given this, I'm curious how you've measured the memory usage caused by
>your program using millions of integers, and why you think reducing the
>size of those integers will help significantly.

  I realise now that I was wrong in assuming this.  However, Python
does use more memory than it needs to to store the data I'm
manipulating.  This is probably caused by their container types,
dictionaries and tuples, however.
  Reducing the amount of memory allocated by any method is my goal
right now, along with increasing the speed at which my program runs.
  I'm using one dictionary to store all of the data, with tuples of
ints as keys and a tuple as the data associated with each key.  The
data tuples contain a few ints and two more dictionaries.
  Can you think of a way to reduce the memory used here?


More information about the Python-list mailing list