You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the Python memory allocator has granularity of 16 bytes, allocating 24 bytes does not save memory in comparison with allocating 32 bytes. One of changes in #82554 was to round the allocated size for list up to 4 items (16 bytes on 32-bit platform and 32 bytes of 64-bit platform). #87740 reverted this. Therefore, if you create an empty list, then extend it with 1 item two times, you will need two allocations, even if the first allocation has a space for yet one item (but list does not know about this).
>>> import sys
>>> a = []
>>> sys.getsizeof(a)
56
>>> a += [1]
>>> sys.getsizeof(a)
64
>>> a += [2]
>>> sys.getsizeof(a)
120
Activity
pythongh-92914: Always round up the size allocated for lists up to 16…
gh-92914: Round the allocated size for lists up to the even number (G…
pythongh-92914: Round the allocated size for lists up to the even num…
pythongh-92914: Round the allocated size for lists up to the even num…
gh-92914: Round the allocated size for lists up to the even number (G…
gh-92914: Round the allocated size for lists up to the even number (G…