I'm trying the below code in a 64 bit system on Python 3.4 to understand the memory consumption of different primitive data types.
import sys
print(sys.getsizeof(45)) # prints 28
print(sys.getsizeof(45.2)) # prints 24
My question is why Integer takes more space than the float value. But on the contrary , In a 32 bit system
import sys
print(sys.getsizeof(45)) # prints 14
print(sys.getsizeof(45.2)) # prints 16
Integer takes less memory than the float. Why is this behavior? Is it depends upon the Operating System as well other than the Chip set size ?
The overheads(PyObject_HEAD
) have doubled, but while the size of ints goes from 32 to 64 bits, the size of floats (doubles) remains 64
32 bit int: overhead = 10 bytes, value = 4 bytes float: overhead = 8 bytes, value = 8 bytes 64 bit int: overhead = 20 bytes, value = 8 bytes float: overhead = 16 bytes, value = 8 bytes
Note that int
can be larger than this if they can't fit in the native datatype
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With