I'm new to python.To find the sizeof an integer i used getsizeof method available in sys module. It returns 24 bytes for integer and 34 bytes for char.
>>> sys.getsizeof(1)
24
>>> sys.getsizeof('a')
34
I feel this size (24 bytes or 34 bytes) is very large to hold an integer or char... I feel that memory is getting wasted much.. Could you please help me in understanding the concept behind this memory management in python.
Because everything is an object, everything has an object bookkeeping overhead. In CPython, it's at least size of a type pointer and reference count for every object. Plus whatever specific objects need for their data. And there's also garbage collector overhead for some objects. Certainly nothing is 'wasted', it's a silly idea.
And there is no char
in Python, 'a'
is a string of length 1.
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