Efficiency of using long integers to hold bitmaps

Raymond Hettinger python at rcn.com
Sun Jul 10 13:43:31 EDT 2005


[Jeff Melvaine]
> I note that I can write expressions like "1 << 100" and the result is stored
> as a long integer, which means it is stored as an integer of arbitrary
> length.  I may need to use a large number of these, and am interested to
> know whether the storage efficiency of long integers is in danger of
> breaking my code if I use too many.  Would I do better to write a class that
> defines bitwise operations on arrays of integers, each integer being assumed
> to contain at most 32 bits?


Both array() objects and long integers are equally space efficient.
In contrast, a list of integers takes up a lot of space (the list is
stored as an array of pointers to individual integer objects).

Raymond




More information about the Python-list mailing list