I am not looking for a constant recording the maximum value representable with an int; I am looking to find out the maximum amount of memory that an int can occupy. Consider the following code:
import sys
def print_and_execute(*args):
for s in args:
print(s, end = " == ")
r = eval(s)
print(r)
return
print_and_execute("type(5) ")
print_and_execute("sys.getsizeof(5)")
i = int()
print_and_execute("i")
print_and_execute("sys.getsizeof(i)")
i = 2937
print_and_execute("i")
print_and_execute("sys.getsizeof(i)")
print_and_execute("sys.maxsize")
print_and_execute("sys.getsizeof(sys.maxsize)")
For my particular machine, the output is:
type(5) == <class 'int'>
sys.getsizeof(5) == 28
i == 0
sys.getsizeof(i) == 24
i == 2937
sys.getsizeof(i) == 28
sys.maxsize == 9223372036854775807
sys.getsizeof(sys.maxsize) == 36
Apparently, some ints are 24 bytes long, others are 28, still others use 36. How many bytes are required to hold an int of any size?