Python-Integer-objects in the range [1,2^30)
need 28
byte, as provided by sys.getsizeof()
and explained for example in this SO-post.>
The int
object only requires 28 bytes, but Python uses 8-byte alignment: memory is allocated in blocks that are multiples of 8 bytes in size. So the actual memory used by each int
object is 32 bytes. See this excellent article on Python memory management for more details.
I don't yet have an explanation for the remaining half byte, but I'll update this if I find one.