Python memory management

I am new to python. To find the size of an integer, I used the getizeof method available in the sys module. It returns 24 bytes for integers and 34 bytes for char.

>>> sys.getsizeof(1) 24 >>> sys.getsizeof('a') 34 

I feel that this size (24 bytes or 34 bytes) is very large to hold an integer or char ... I feel that memory is badly lost. Could you help me understand the concept of memory management in python.

+6
source share
1 answer

Since everything is an object, everything has an overhead for the objects. In CPython, at least it has the size of a type pointer and reference count for each object. In addition, any specific objects are needed for their data. And some facilities have a garbage collector. Of course, nothing is "wasted", this is a stupid idea.

And in Python there is no char , 'a' is a string of length 1.

+15
source

Source: https://habr.com/ru/post/892432/


All Articles